LS_DYNA_Family issue in VTK compilation in cygwin - cygwin

I am trying to compile in VTK5.10 in windows cygwin and I am receiving following error messages. Any resolution please:
[ 27%] Built target vtkexoIIc
[ 27%] Building CXX object Utilities/LSDyna/CMakeFiles/LSDyna.dir/LSDynaFamily.cxx.o
/cygdrive/c/cygwin64/VTK5.10.1/Utilities/LSDyna/LSDynaFamily.cxx: In function ‘int {anonymous}::LS_DYNA_STAT(const char*, {anonymous}::stat64&)’:
/cygdrive/c/cygwin64/VTK5.10.1/Utilities/LSDyna/LSDynaFamily.cxx:44:25: error: invalid use of incomplete type ‘struct {anonymous}::stat64’
return stat64(fname,&s);
^
/cygdrive/c/cygwin64/VTK5.10.1/Utilities/LSDyna/LSDynaFamily.cxx:41:44: error: forward declaration of ‘struct {anonymous}::stat64’
int LS_DYNA_STAT(const char* fname, struct stat64& s)
^
/cygdrive/c/cygwin64/VTK5.10.1/Utilities/LSDyna/LSDynaFamily.cxx: In member function ‘int LSDynaFamily::ScanDatabaseDirectory()’:
/cygdrive/c/cygwin64/VTK5.10.1/Utilities/LSDyna/LSDynaFamily.cxx:229:17: error: aggregate ‘{anonymous}::stat64 st’ has incomplete type and cannot be defined
struct stat64 st;
^
Utilities/LSDyna/CMakeFiles/LSDyna.dir/build.make:54: recipe for target 'Utilities/LSDyna/CMakeFiles/LSDyna.dir/LSDynaFamily.cxx.o' failed
make[2]: *** [Utilities/LSDyna/CMakeFiles/LSDyna.dir/LSDynaFamily.cxx.o] Error 1
CMakeFiles/Makefile2:2418: recipe for target 'Utilities/LSDyna/CMakeFiles/LSDyna.dir/all' failed
make[1]: *** [Utilities/LSDyna/CMakeFiles/LSDyna.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Solved the problem. I think the issue was with some if_else conditions related to some settings for other environments like POSIX, FreeBSD. I am not an expert so by hit and trial, I commented some lines in the file LSDynaFamily.cxx.
Line number 44:
//return stat64(fname,&s);
Part of line number 227 onwards was modified as below:
//#elif USE_STAT_64
//struct stat64 st;
Part of line number 240:
#if defined (WIN32) && VTK_SIZEOF_ID_TYPE==8
struct __stat64 st;
//#elif USE_STAT_64
//struct stat64 st;
#else
struct stat st;
#endif
while ( tryAdapt >= 0 )
{
tmpFile = vtkLSGetFamilyFileName( this->DatabaseDirectory.c_str(),
this->DatabaseBaseName,
adaptLevel,
filenum );
/* if ( LS_DYNA_STAT( tmpFile.c_str(), st) == 0 )
{
if ( adapted )
{
this->Adaptations.push_back( (int)this->Files.size() );
adapted = false;
}
this->Files.push_back( tmpFile );
this->FileSizes.push_back( st.st_size );
this->FileAdaptLevels.push_back( adaptLevel );
tryAdapt = 1;
++filenum;
}
else
{*/
--tryAdapt;
++adaptLevel;
filenum = 0;
adapted = true;
// }
}
return this->Files.size() == 0;
}

Related

Linux kernel tracepoint: Symbol undefined when connecting a probe function to tracepoint

I'm now practicing with Linux tracepoint.
Basically, I'm trying to make a kernel module where a probe function is defined and connected to a tracepoint("trace_netif_receive_skb" in kernel source file dev.c) in Linux Kernel.
When I compiled and ran the kernel module on SLES11, it works well. But when I did the same things on SLES12, it complained that the symbol is undefined.
The kernel module source code is:
1 #include <linux/module.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/skbuff.h>
5 #include <trace/events/net.h>
6
7 static void probe(void *ignore, struct sk_buff *skb)
8 {
9 printk(KERN_INFO "probe, protocol[0X%04X]\n", ntohs(skb->protocol));
10 }
11
12 static int __init init_tracepoint(void)
13 {
14 if (0 != register_trace_netif_receive_skb(probe, NULL))
15 {
16 printk(KERN_INFO "tracepoint init fails\n");
17 }
18
19 printk(KERN_INFO "tracepoint init succeeds\n");
20 return 0;
21 }
22
23 static void __exit cleanup_tracepoint(void)
24 {
25 unregister_trace_netif_receive_skb(probe, NULL);
26 tracepoint_synchronize_unregister();
27
28 printk(KERN_INFO "tracepoint exit\n");
29 }
30
31 module_init(init_tracepoint);
32 module_exit(cleanup_tracepoint);
33
34 MODULE_LICENSE("GPL");
This is the output on SLES11, no error is reported.
suse11-1:~/works/tracepoint # make
make -C /lib/modules/3.0.76-0.11-default/build M=/root/works/tracepoint modules
make[1]: Entering directory `/usr/src/linux-3.0.76-0.11-obj/x86_64/default'
make -C ../../../linux-3.0.76-0.11 O=/usr/src/linux-3.0.76-0.11-obj/x86_64/default/. modules
CC [M] /root/works/tracepoint/tracepoint.o
Building modules, stage 2.
MODPOST 1 modules
CC /root/works/tracepoint/tracepoint.mod.o
LD [M] /root/works/tracepoint/tracepoint.ko
make[1]: Leaving directory `/usr/src/linux-3.0.76-0.11-obj/x86_64/default'
suse11-1:~/works/tracepoint # insmod tracepoint.ko
This is the output on SLES12, it says: WARNING: "__tracepoint_netif_receive_skb" [/root/works/codes/tracepoint/tracepoint.ko] undefined! And I can find "Unknown symbol __tracepoint_netif_receive_skb (err 0)" in /var/log/messages.
suse12-1:~/works/codes/tracepoint # make
make -C /lib/modules/4.4.21-69-default/build M=/root/works/codes/tracepoint modules
make[1]: Entering directory '/usr/src/linux-4.4.21-69-obj/x86_64/default'
CC [M] /root/works/codes/tracepoint/tracepoint.o
Building modules, stage 2.
MODPOST 1 modules
WARNING: "__tracepoint_netif_receive_skb" [/root/works/codes/tracepoint/tracepoint.ko] undefined!
CC /root/works/codes/tracepoint/tracepoint.mod.o
LD [M] /root/works/codes/tracepoint/tracepoint.ko
make[1]: Leaving directory '/usr/src/linux-4.4.21-69-obj/x86_64/default'
suse12-1:~/works/codes/tracepoint #
suse12-1:~/works/codes/tracepoint # insmod tracepoint.ko
insmod: ERROR: could not insert module tracepoint.ko: Unknown symbol in module
I checked the kernel source code of tracepoint framework of both SLES11 and SLES12, the "__tracepoint_##name" defined "include/linux/tracepoint.h" is not exported unless EXPORT_TRACEPOINT_SYMBOL() or EXPORT_TRACEPOINT_SYMBOL_GPL() is called, but I didn't find any place in linux kernel codes where EXPORT_TRACEPOINT_SYMBOL(netif_receive_skb) or EXPORT_TRACEPOINT_SYMBOL_GPL(netif_receive_skb) is called to export symbol __tracepoint_netif_receive_skb.
Then why I didn't meet the problem on SLES11? And how can I get it work on SLES12?
Use for_each_kernel_tracepoint to find target tracepoint and register probe, works for me, good luck.
struct tp_reg {
const char *name;
struct tracepoint *tp;
void *fn;
};
static void each_tracepoint(struct tracepoint *tp, void *priv)
{
struct tp_reg *regs = (struct tp_reg *)priv;
int i;
for (i = 0; regs[i].name; ++i) {
if (strcmp(tp->name, regs[i].name) == 0) {
if (tracepoint_probe_register(tp, regs[i].fn, NULL) == 0) {
regs[i].tp = tp;
}
}
}
}
static void unregister_tp(struct tp_reg *regs)
{
int i;
for (i = 0; regs[i].name; ++i) {
if (regs[i].tp) {
tracepoint_probe_unregister(regs[i].tp, regs[i].fn, NULL);
regs[i].tp = NULL;
}
}
tracepoint_synchronize_unregister();
}
static int register_tp(struct tp_reg *regs)
{
int i;
for_each_kernel_tracepoint(each_tracepoint, regs);
for (i = 0; regs[i].name; ++i) {
if (regs[i].tp == NULL) {
printk(KERN_ALERT "trace point %s not found.\n", regs[i].name);
unregister_tp(regs);
return 1;
}
}
return 0;
}
Sample code:
static void probe_callback(void *ignore, struct pt_regs *regs, long id)
{
if (id == __NR_execve) {
char file[100];
if (strncpy_from_user(file, (void *)PT_REGS_PARM1(regs), sizeof(file)) < 0)
return;
printk(KERN_INFO "execve %s", file);
}
}
static struct tp_reg myreg[] = {
{ .name = "sys_enter", .fn = (void *)probe_callback },
{ .name = NULL }
};
static int __init init_tracepoint(void)
{
return register_tp(myreg);
}
static void __exit cleanup_tracepoint(void)
{
unregister_tp(myreg);
}

packet.c:98:2: error: 'writebuf' undeclared (first use in this function)

I'm trying to compile dropbear for windows before I compiled it but now that I try to recompile it and format my previous pc, install cygwin and what is necessary but when I execute the make command, it throws me that error. but I do not understand why it says that it is not declared if it is clearly seen there, I would appreciate your help.
ERROR: "packet.c: In function 'write_packet':
packet.c:98:2: error: 'writebuf' undeclared (first use in this function)
writebuf = (buffer*)examine(&ses.writequeue);"
CODE:
#ifdef HAVE_WRITEV
/* 50 is somewhat arbitrary */
unsigned int iov_count = 50;
struct iovec iov[50];
#else
int len;
buffer* writebuf;
int packet_type;
#endif
TRACE2(("enter write_packet"))
dropbear_assert(!isempty(&ses.writequeue));
#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
packet_queue_to_iovec(&ses.writequeue, iov, &iov_count);
/* This may return EAGAIN. The main loop sometimes
calls write_packet() without bothering to test with select() since
it's likely to be necessary */
written = writev(ses.sock_out, iov, iov_count);
if (written < 0) {
if (errno == EINTR || errno == EAGAIN) {
TRACE2(("leave write_packet: EINTR"))
return;
} else {
dropbear_exit("Error writing: %s", strerror(errno));
}
}
packet_queue_consume(&ses.writequeue, written);
ses.writequeue_len -= written;
if (written == 0) {
ses.remoteclosed();
}
#else /* No writev () */
/* Get the next buffer in the queue of encrypted packets to write*/
writebuf = (buffer*)examine(&ses.writequeue);
/* The last byte of the buffer is not to be transmitted, but is
* a cleartext packet_type indicator */
packet_type = writebuf->data[writebuf->len-1];
len = writebuf->len - 1 - writebuf->pos;
TRACE2(("write_packet type %d len %d/%d", packet_type,
len, writebuf->len-1))
dropbear_assert(len > 0);
The problem seems due that the definition protected by a single check
#ifdef HAVE_WRITEV
while the usage is behind a multiple check
#if defined(HAVE_WRITEV) && (defined(IOV_MAX) || defined(UIO_MAXIOV))
HAVE_WRITEV is defined in config.h on cygwin, so the definition is skipped but the check for usage fails and writebuf is used.
It seems a upstream bug.

error: ‘struct task_struct’ has no member named ‘it_virt_value’

I am trying to create a system call in Linux ubuntu-studio that has the following functionality:
bring virtual memory the larger process and how much bytes it occupies.
below is the implementation code of the system call:
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/sched.h>
struct pid_size{
int pid;
unsigned long size;
};
struct pid_size pid maiorMemoriaVirtual(void)
{
struct task_struct *task;
struct task_struct *maior = NULL;
for_each_process(task)
{
if(maior == NULL)
maior = task;
else if(task->it_virt_value > maior->it_virt_value)
maior = task;
}
struct pid_size retorno;
retorno.pid = maior->pid;
retorno.size = maior->it_virt_value;
return retorno;
}
When compiling to try compiling the kernel got the following error:
kernel/maiorMemoriaVirtual.c: In function ‘sys_maiorMemoriaVirtual’:
kernel/maiorMemoriaVirtual.c:19:21: error: ‘struct task_struct’ has no member named ‘it_virt_value’
else if(task->it_virt_value > maior->it_virt_value)
^
kernel/maiorMemoriaVirtual.c:19:44: error: ‘struct task_struct’ has no member named ‘it_virt_value’
else if(task->it_virt_value > maior->it_virt_value)
^
kernel/maiorMemoriaVirtual.c:23:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
struct pid_size retorno;
^
kernel/maiorMemoriaVirtual.c:25:25: error: ‘struct task_struct’ has no member named ‘it_virt_value’
retorno.size = maior->it_virt_value;
^
make[1]: ** [kernel/maiorMemoriaVirtual.o] Erro 1
I came across a similar problem while working on an assignment and I have realized that there are quite a few changes that have been made to the definition of the 'task_struct' structure.
My guess is that you are looking for accumulated virtual memory usage. You might find this link useful. Accumulated Virtual Memory usage
Link to the task_struct definition in kernel 2.6.36

netlink_kernel_create not working while compiling in kernel 3.8 x

presently i am working on a research project in which we are trying to run a wireless netwok protocal namely aodvuu developed by uppasala university. The protocal was developed in linux kernel version 2.4 x and now we are trying to run it on kernel version 3.8. The following is the corresponding kernel code which is facing problem (kaodv-netlink.c).
#include <linux/module.h>
#include <net/sock.h>
#include <linux/netlink.h>
#include <linux/skbuff.h>
#define NETLINK_USER 31
struct sock *nl_sk = NULL;
static void hello_nl_recv_msg(struct sk_buff *skb) {
struct nlmsghdr *nlh;
int pid;
struct sk_buff *skb_out;
int msg_size;
char *msg="Hello from kernel";
int res;
printk(KERN_INFO "Entering: %s\n", __FUNCTION__);
msg_size=strlen(msg);
nlh=(struct nlmsghdr*)skb->data;
printk(KERN_INFO "Netlink received msg payload:%s\n",(char*)nlmsg_data(nlh));
pid = nlh->nlmsg_pid; /*pid of sending process */
skb_out = nlmsg_new(msg_size,0);
if(!skb_out)
{
printk(KERN_ERR "Failed to allocate new skb\n");
return;
}
nlh=nlmsg_put(skb_out,0,0,NLMSG_DONE,msg_size,0);
NETLINK_CB(skb_out).dst_group = 0; /* not in mcast group */
strncpy(nlmsg_data(nlh),msg,msg_size);
res=nlmsg_unicast(nl_sk,skb_out,pid);
if(res<0)
printk(KERN_INFO "Error while sending bak to user\n");
}
static int __init hello_init(void) {
printk("Entering: %s\n",__FUNCTION__);
/* This is for 3.6 kernels and above.
struct netlink_kernel_cfg cfg = {
.input = hello_nl_recv_msg,
};
nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, &cfg);*/
nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, 0, hello_nl_recv_msg,NULL,THIS_MODULE);
if(!nl_sk)
{
printk(KERN_ALERT "Error creating socket.\n");
return -10;
}
return 0;
}
static void __exit hello_exit(void) {
printk(KERN_INFO "exiting hello module\n");
netlink_kernel_release(nl_sk);
}
module_init(hello_init); module_exit(hello_exit);
MODULE_LICENSE("GPL");
Error i am getting is
timer_queue.o aodv_socket.o aodv_hello.o aodv_neighbor.o aodv_timeout.o routing_table.o seek_list.o aodv_rreq.o aodv_rrep.o aodv_rerr.o nl.o locality.o
make -C /home/lp3/aodvuu096/lnx KERNEL_DIR=/lib/modules/3.8.0-31-generic/build KCC=gcc XDEFS=-DDEBUG
make[1]: Entering directory `/home/lp3/aodvuu096/lnx'
make -C /lib/modules/3.8.0-31-generic/build M=/home/lp3/aodvuu096/lnx modules
make[2]: Entering directory `/usr/src/linux-headers-3.8.0-31-generic'
CC [M] /home/lp3/aodvuu096/lnx/kaodv-mod.o
CC [M] /home/lp3/aodvuu096/lnx/kaodv-debug.o
CC [M] /home/lp3/aodvuu096/lnx/kaodv-netlink.o
/home/lp3/aodvuu096/lnx/kaodv-netlink.c: In function ‘kaodv_netlink_init’:
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:372:21: warning: passing argument 3 of ‘netlink_kernel_create’ from incompatible pointer type [enabled by default]
include/linux/netlink.h:48:1: note: expected ‘struct netlink_kernel_cfg *’ but argument is of type ‘void (*)(struct sk_buff *)’
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:372:21: error: too many arguments to function ‘netlink_kernel_create’
include/linux/netlink.h:48:1: note: declared here
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:374:13: error: invalid storage class for function ‘kaodv_netlink_rcv_sk’
/home/lp3/aodvuu096/lnx/kaodv-netlink.c: In function ‘kaodv_netlink_rcv_sk’:
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:378:14: error: ‘recv_cmd’ undeclared (first use in this function)
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:378:14: note: each undeclared identifier is reported only once for each function it appears in
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:382:1: error: incompatible type for argument 3 of ‘netlink_kernel_create’
include/linux/netlink.h:48:1: note: expected ‘struct netlink_kernel_cfg *’ but argument is of type ‘struct netlink_kernel_cfg’
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:386:3: warning: ‘return’ with a value, in function returning void [enabled by default]
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:389:1: warning: ‘return’ with a value, in function returning void [enabled by default]
/home/lp3/aodvuu096/lnx/kaodv-netlink.c: In function ‘kaodv_netlink_init’:
/home/lp3/aodvuu096/lnx/kaodv-netlink.c:374:1: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
make[3]: *** [/home/lp3/aodvuu096/lnx/kaodv-netlink.o] Error 1
make[2]: *** [_module_/home/lp3/aodvuu096/lnx] Error 2
make[2]: Leaving directory `/usr/src/linux-headers-3.8.0-31-generic'
make[1]: *** [kaodv.ko] Error 2
make[1]: Leaving directory `/home/lp3/aodvuu096/lnx'
make: *** [kaodv] Error 2
lp3#lp3-Latitude-E5420:~/aodvuu096$
Comment out this line to fix this error.
nl_sk = netlink_kernel_create(&init_net, NETLINK_USER, 0, hello_nl_recv_msg,NULL,THIS_MODULE);

VC warning 4365 seems to be inconsistent

My question is: why does VC emit warning 4365 for only one of the commented lines below, and not the other?
#pragma warning(1: 4365)
void test1(const unsigned short) {}
unsigned short test2() { return 0; }
int main()
{
const unsigned short a = 0;
const unsigned short b = 0;
test1(a + b); // This line gives no warning
test1(test2() + b); // This line gives C4365
return 0;
}
Tested under VS2010 and VS2012 Express.
For reference, the full warning text is this:
warning C4365: 'argument' : conversion from 'int' to 'const unsigned short', signed/unsigned mismatch
Using Clang 3.3 (through Clang-Win32 and ClangVSx), no warnings are reported in this code (except of course the unknown pragma).

Resources