Interesting issue I had recently with my current project. We are using "memory tools", substituting calloc, malloc, realloc call with some custom code and do whatever you like there.
And here is the issue reproduced on small app:
---------------------------------------------------------------
Fri Oct 31 17:26:24
[vivanov@galatea MEMORY_WRAP]$ cat main_nothreads.c
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
void * calloc(size_t n, size_t sz)
{
printf("start\n");
void *ptr;
void *(*real_malloc)(size_t, size_t);
real_malloc = (void *(*)(size_t, size_t))dlsym(RTLD_NEXT, "calloc");
ptr = (*real_malloc)(n, sz);
printf("end\n");
return ptr;
}
int main(int argc, char *argv[])
{
void* mem = calloc(2, 20);
printf ("%p\n", mem);
return 0;
}
Fri Oct 31 17:26:29
[vivanov@galatea MEMORY_WRAP]$ gcc -ldl main_nothreads.c
Fri Oct 31 17:26:46
[vivanov@galatea MEMORY_WRAP]$ ./a.out
start
end
0x9bb0008
Fri Oct 31 17:26:49
[vivanov@galatea MEMORY_WRAP]$ gcc -ldl -lpthread main_nothreads.c
---------------------------------------------------------------
This time app. Will fail. Here is back trace from debugger:
---------------------------------------------------------------
[New Thread -1208293696 (LWP 766)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1208293696 (LWP 766)]
0x0078b8ec in _IO_new_file_write () from /lib/libc.so.6
(gdb) bt
#0 0x0078b8ec in _IO_new_file_write () from /lib/libc.so.6
#1 0x0078b5b5 in new_do_write () from /lib/libc.so.6
#2 0x0078b89f in _IO_new_do_write () from /lib/libc.so.6
#3 0x0078c1a8 in _IO_new_file_overflow () from /lib/libc.so.6
#4 0x0078eb33 in __overflow () from /lib/libc.so.6
#5 0x00782b9b in puts () from /lib/libc.so.6
#6 0x08048476 in calloc ()
#7 0x0089833c in _dlerror_run () from /lib/libdl.so.2
#8 0x00897d93 in dlsym () from /lib/libdl.so.2
#9 0x0804848a in calloc ()
#10 0x0089833c in _dlerror_run () from /lib/libdl.so.2
#11 0x00897d93 in dlsym () from /lib/libdl.so.2
#12 0x0804848a in calloc ()
#13 0x0089833c in _dlerror_run () from /lib/libdl.so.2
#14 0x00897d93 in dlsym () from /lib/libdl.so.2
#15 0x0804848a in calloc ()
#16 0x0089833c in _dlerror_run () from /lib/libdl.so.2
#17 0x00897d93 in dlsym () from /lib/libdl.so.2
#18 0x0804848a in calloc ()
#19 0x0089833c in _dlerror_run () from /lib/libdl.so.2
#20 0x00897d93 in dlsym () from /lib/libdl.so.2
#21 0x0804848a in calloc ()
---------------------------------------------------------------
The problem is that dlsym when linked with pthreads is calling changed calloc and we enter infinite loop. When we are not linking with pthreads is seems like dlsym doesn't call calloc at all. It's a normal issue and glibc guys know about it:
http://sourceware.org/ml/libc-help/2008-11/msg00000.html
It can be fixed something like this:
...
const int extra_mem_size = 20;
static char extra_mem[extra_mem_size];
...
//-----------------------------------------------------------------------------
void * calloc(size_t num, size_t sz)
{
static bool memUsed; // Counting on default initialization to 0
if (!memUsed)
{
if(sz > extra_mem_size) {
printf("ERROR: calloc static buffer issue!!!\n");
printf("Check size of dl_action_result structure.\n");
abort();
}
memUsed = true;
memset(extra_mem, 0, sz);
return (void *) extra_mem;
};
...
Here is a few interesting links on linux threads, NPTL:
Linux threading models compared: LinuxThreads and NPTL.
Explaining LD_ASSUME_KERNEL.
Migrating to Linux kernel 2.6 -- Part 5: Migrating apps to the 2.6 kernel and NPTL.
Tuesday, November 11, 2008
Monday, September 8, 2008
Tuesday, July 22, 2008
Fedora 8 2.6.24.4-64.fc8 and vmware workstation 5.5
A few tricks I used to make vmware running on my box.
[root@pcvitaliy ~]# uname -a
Linux pcvitaliy 2.6.24.4-64.fc8 #1 SMP Sat Mar 29 09:54:46 EDT 2008 i686 i686 i386 GNU/Linux
[root@pcvitaliy ~]#
Usual procedure with vmware installation under not supported OSs using any to any package.
I used vmware-any-any-update-116.tgz from:
http://groups.google.com/group/vmkernelnewbies/files
I installed VMware-workstation-5.5-setup.tar.gz.
After successful installation you will find that it fails to start with the following message:
[vitaliy@pcvitaliy libpng12.so.0]$ vmware
vmware: xcb_lock.c:77: _XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy->request)) >= 0)' failed.
[vitaliy@pcvitaliy libpng12.so.0]$
The problem is in X code stuff. To correct it we can downgrade X package to more older or to do the following. Get http://glasstheplanet.org/debian/libX11.so.6
$VMWARE_PREFIX is wherever you told vmware to install. Default is /usr
mkdir $VMWARE_PREFIX/lib/vmware/lib/libX11.so.6
cp libX11.so.6 $VMWARE_PREFIX/lib/vmware/lib/libX11.so.6/libX11.so.6
Then edit $VMWARE_PREFIX/lib/vmware/lib/wrapper-gtk24.sh. Look for the part that looks like this: (For 1.0.6 this is line 65)
vm_append_lib 'libfreetype.so.6'
vm_append_lib 'libXft.so.2'
vm_append_lib 'libXrender.so.1'
Add a line after these that says:
vm_append_lib 'libX11.so.6'
You are all set. Now it should be OK.
[root@pcvitaliy ~]# uname -a
Linux pcvitaliy 2.6.24.4-64.fc8 #1 SMP Sat Mar 29 09:54:46 EDT 2008 i686 i686 i386 GNU/Linux
[root@pcvitaliy ~]#
Usual procedure with vmware installation under not supported OSs using any to any package.
I used vmware-any-any-update-116.tgz from:
http://groups.google.com/group/vmkernelnewbies/files
I installed VMware-workstation-5.5-setup.tar.gz.
After successful installation you will find that it fails to start with the following message:
[vitaliy@pcvitaliy libpng12.so.0]$ vmware
vmware: xcb_lock.c:77: _XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy->request)) >= 0)' failed.
[vitaliy@pcvitaliy libpng12.so.0]$
The problem is in X code stuff. To correct it we can downgrade X package to more older or to do the following. Get http://glasstheplanet.org/debian/libX11.so.6
$VMWARE_PREFIX is wherever you told vmware to install. Default is /usr
mkdir $VMWARE_PREFIX/lib/vmware/lib/libX11.so.6
cp libX11.so.6 $VMWARE_PREFIX/lib/vmware/lib/libX11.so.6/libX11.so.6
Then edit $VMWARE_PREFIX/lib/vmware/lib/wrapper-gtk24.sh. Look for the part that looks like this: (For 1.0.6 this is line 65)
vm_append_lib 'libfreetype.so.6'
vm_append_lib 'libXft.so.2'
vm_append_lib 'libXrender.so.1'
Add a line after these that says:
vm_append_lib 'libX11.so.6'
You are all set. Now it should be OK.
Tuesday, May 20, 2008
Tuesday, March 18, 2008
"First Post"
Just realized that I didn't say my usual to bloggers "first post" word. So here it's...
I'm going to share some stuff that is interesting to me, hope there will be people that will like it as well.
I'm going to share some stuff that is interesting to me, hope there will be people that will like it as well.
Monday, March 10, 2008
iPhone posts
I'm one of those lucky guys who owns Apple's iPhone. To tell you the truth it's not as good as they say about it. After normal usage of the device for about 4 month I can tell that as phone it's not convenient and handy as other devices from the same class. But, anyway, my blog is intended to be more technical then just my thoughts and impressions.
I'm going to post a few items about iPhone related things mainly under Linux(Fedora 8 for now).
I'm living currently in Lviv, Ukraine so, certainly, I'm using unlocked/hacked iPhone. Was among those who bought 1.1.1OTB in apple store near Boston, MA. It's easy to unlock it, a lot of things changed since then... Many guys become famous, hi to zibri and Slava Karpenko:). My favorite links on subj:
http://www.iphones.ru/
http://www.hackint0sh.org/forum/indexpage.php
http://www.ziphone.org/
The first thing you will need is iTunes. There is no Linux native app. that's why we need to make iTunes work here somehow.
Going to try it under Wine.
I'm going to post a few items about iPhone related things mainly under Linux(Fedora 8 for now).
I'm living currently in Lviv, Ukraine so, certainly, I'm using unlocked/hacked iPhone. Was among those who bought 1.1.1OTB in apple store near Boston, MA. It's easy to unlock it, a lot of things changed since then... Many guys become famous, hi to zibri and Slava Karpenko:). My favorite links on subj:
http://www.iphones.ru/
http://www.hackint0sh.org/forum/indexpage.php
http://www.ziphone.org/
The first thing you will need is iTunes. There is no Linux native app. that's why we need to make iTunes work here somehow.
Going to try it under Wine.
Saturday, March 8, 2008
DELL Vostro 1400(210-19024) && Fedora 8
Characteristics:
-----
CPU: Core 2 Duo T7250 2.0GHz(2MB cache 800MHz FSB)
RAM: 2GB (2x 1024MB DDR2 667MHz)
HDD: 160GB
Optical drive: DVD-Super-Multi
Display: 14.1" WXGA (1280x800)
Graphics: Intel GMA3100 256MB
Wireless: Wi-Fi, Bluetooth 2.0
Ports, slots: 1 x Express Card / 4 x USB / IEEE1394 / VGA / S-Video / RJ-11 / RJ-45 / Media Direct / Headphones / Mic-in / Card Reader 8in1
Other: Camera 2.0 MPix, infrared slot
OS: Microsoft Vista Basic
Weight: 2.4 kg
-----
A few issues that I had to solve after Fedora installation.
Network/Wi-Fi:
To make wi-fi work do the following.
Install ndiswrapper from sources: http://ndiswrapper.sourceforge.net/joomla/
Disable free drivers by adding the following to /etc/modprobe.d/blacklist:
blacklist b43
blacklist ssb
Download windows driver from Dell site for your card:
$lspci | grep -i wlan
0c:00.0 Network controller: Broadcom Corporation BCM94311MCG wlan mini-PCI (rev 01)
I used this one.
Unpack it using unzip and install:
$ndiswrapper -i R151519/DRIVER/bcmwl5.inf
Check that it's installed successfully:
$ ndiswrapper -l
bcmwl5 : driver installed
device (14E4:4311) present (alternate driver: ssb)
Now load new driver:
$depmod -a
$modprobe ndiswrapper
Now it's time to install NetworkManager app. It is perfect for laptops and multiple connections to different networks. Install it and configure to run at start-up:
$yum install NetworkManager
$chkconfig --level 345 NetworkManager on
$/etc/init.d/NetworkManager start
Also disable auto start of dhcpclient in network scritps by setting ONBOOT=no in /etc/sysconfig/network-scripts/ifcfg-wlan0, etc.
And, finally, make your system load ndiswrapper automatically each time on startup:
$ndiswrapper -m
P.S.
ndiswrapper support is broken in 2.6.24 kernel. Interesting discussion can be found at LKML:
http://lkml.org/lkml/2008/2/28/408
So, if you like latest kernel then you would have to play with GPL-only symbols kernel customization.
Subscribe to:
Comments (Atom)

