[Cs-dev] segmentation fault when creating very simple plugin opcode
Date | 2012-09-01 10:59 |
From | obaudouin |
Subject | [Cs-dev] segmentation fault when creating very simple plugin opcode |
Hello, I get a segfault with this plugin opcode, and I don't understand why... The compilation is OK, and the opcode is recognized by Csound. ------------------------------------SCONStruct-------------------------- "Opcodes/testread.c" added ------------------------------------------- *.csd----------------------------------------------- k1 testRead --------------------------------------gdb backtrace----------------------------------- Program received signal SIGSEGV, Segmentation fault. 0x000000000040beae in kperf (csound=0x8daf20) at Top/csound.c:1621 1621 (*csound->pds->opadr)(csound, csound->pds); /* run each opcode */ (gdb) bt #0 0x000000000040beae in kperf (csound=0x8daf20) at Top/csound.c:1621 #1 0x000000000040c2dc in csoundPerform (csound=0x8daf20) at Top/csound.c:1731 #2 0x0000000000405c20 in main (argc=2, argv=0x7fffffffe598) at frontends/csound/csound_main.c:139 -----------------------------------------------testread.c---------------------------------------------- #include "csdl.h" // --> "Opcodes/testread.c" in SCONStruct typedef struct { OPDS h; MYFLT *k1; } TESTREAD; int testRead(CSOUND *csound, TESTREAD *p) { MYFLT *k1; double val = 50; *p->k1 = val; return OK; } static OENTRY localops[] = { { "testRead", sizeof(testRead), 2, "k", "", (SUBR)NULL, (SUBR)testRead, (SUBR)NULL } }; LINKAGE ----- Olivier Baudouin, PhD http://olivierbaudouin.com MINT-OMF Paris-Sorbonne -- View this message in context: http://csound.1045644.n5.nabble.com/segmentation-fault-when-creating-very-simple-plugin-opcode-tp5715349.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2012-09-01 12:27 |
From | Richard Dobson |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
On 01/09/2012 10:59, obaudouin wrote: > Hello, > > I get a segfault with this plugin opcode, and I don't understand why... The > compilation is OK, and the opcode is recognized by Csound. > .. Two problems: Firstly: static OENTRY localops[] = { { "testRead", sizeof(testRead), 2, "k", "", (SUBR)NULL, (SUBR)testRead, (SUBR)NULL } }; The second field should be sizeof(TESTREAD). This is bound to elicit an access violation, and is very likely the one that is actually hitting, when Csound tries to fit all of your struct into an impossibly small space, and then access various bits of it. Secondly, in that struct: you have declared a ~pointer~ to MYFLT, "k1": > typedef struct { > OPDS h; > MYFLT *k1; > } TESTREAD; > But it is not initialised to point to anything (no init function provided). So accessing it below (when execution gets that far) will also cause an access violation: > *p->k1 = val; So there is the classic question - what are you trying to do? On the face of it, k1 should be a plain MYFLT, not a pointer. If it is meant to point to some external block, that block needs to be known to exist, e.g. allocated via an init function. Richard Dobson ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2012-09-01 13:19 |
From | jpff@cs.bath.ac.uk |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
Richard's first remark is certainly true. I think the second is not the case as the variable is allocated in the instrument setup ==John ff > On 01/09/2012 10:59, obaudouin wrote: >> Hello, >> >> I get a segfault with this plugin opcode, and I don't understand why... >> The >> compilation is OK, and the opcode is recognized by Csound. >> > .. > > Two problems: > > Firstly: > static OENTRY localops[] = { > { "testRead", sizeof(testRead), 2, "k", "", > (SUBR)NULL, (SUBR)testRead, (SUBR)NULL } > }; > > > The second field should be sizeof(TESTREAD). This is bound to elicit an > access violation, and is very likely the one that is actually hitting, > when Csound tries to fit all of your struct into an impossibly small > space, and then access various bits of it. > > Secondly, in that struct: > > you have declared a ~pointer~ to MYFLT, "k1": > >> typedef struct { >> OPDS h; >> MYFLT *k1; >> } TESTREAD; >> > > But it is not initialised to point to anything (no init function > provided). > > So accessing it below (when execution gets that far) will also cause an > access violation: > >> *p->k1 = val; > > > So there is the classic question - what are you trying to do? On the > face of it, k1 should be a plain MYFLT, not a pointer. If it is meant to > point to some external block, that block needs to be known to exist, > e.g. allocated via an init function. > > Richard Dobson > > > > > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Csound-devel mailing list > Csound-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/csound-devel > > > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2012-09-01 15:46 |
From | Richard Dobson |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
Looks like I need to relearn Csound internals. Where/how would this be set, in the absence of a user-supplied init func? Richard Dobson On 01/09/2012 13:19, jpff@cs.bath.ac.uk wrote: > Richard's first remark is certainly true. I think the second is not the > case as the variable is allocated in the instrument setup > ==John ff > ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2012-09-01 16:13 |
From | Steven Yi |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
Hi Richard, The values after OPDS are the values corresponding to the out- and in-args to the opcode. They are set when an instance of the instrument is loaded. The instance function allocates the single block of memory that was pre-calculated by otran for the instance (sum of k-vars, a-vars, f-vars, etc. used in the instrument), and that block is indexed into and parts assigned to the opcode's memblock instance. In CS5, the indexes for that that block of memory are pre-calculated and the variable names discarded. In the CS6 typesystem branch, the block of memory is more dynamic, in that the variables retain their names, so as to support introspection of the instrument's variables as well as dynamic modification of the instrument's definition. Hope that helps! steven On Sat, Sep 1, 2012 at 3:46 PM, Richard Dobson |
Date | 2012-09-01 17:51 |
From | Richard Dobson |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
Thanks - momentary mental aberration. Just been such a long time since I looked at the sources... Richard Dobson On 01/09/2012 16:13, Steven Yi wrote: > Hi Richard, > > The values after OPDS are the values corresponding to the out- and > in-args to the opcode. ... ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |
Date | 2012-09-02 11:11 |
From | obaudouin |
Subject | Re: [Cs-dev] segmentation fault when creating very simple plugin opcode |
I have modified OENTRY and now it runs well! Thanks a lot for the tip. Olivier. ----- Olivier Baudouin, PhD http://olivierbaudouin.com MINT-OMF Paris-Sorbonne -- View this message in context: http://csound.1045644.n5.nabble.com/segmentation-fault-when-creating-very-simple-plugin-opcode-tp5715349p5715373.html Sent from the Csound - Dev mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net |