Mail Archives: cygwin-apps/2001/06/26/00:49:52
Hi, on porting the kde 1 audioserver I have a problem calling fopen. On
opening any files it returns a ENOMEM error.
Like shown in the below code fragmenzt kaudioserver.exe forks and starts
maudio.exe. Maudio.exe then waits for incoming requests over shared memory.
After receivings playing requests it tries to open the relating wav file,
which fails.
------------<snip>---------------------
// --- decoupling from shell finished ---
fprintf(stderr, "%s: 2. fork() starting\n", argv[0]);
forkret=fork();
if (forkret==0) {
fprintf(stderr, "%s: starting audio server %x\n", argv[0],forkret);
// start audio server "maudio"
execvp( MaudioText, Opts);
fprintf(stderr,"Failed starting audio server!\n");
}
else if (forkret > 0) {
fprintf(stderr, "%s: after 2. fork() %x\n", argv[0],forkret);
// Controlling process ("maudio")
maudioPID = forkret;
-------------<snip>-------------------------
maudio.exe
-------------<snip>-------------------------
audiofile = fopen(fname, "r");
if (!audiofile) {
fprintf(stderr,"fname %s, errno=%d\n!",fname,errno);
cerr << "maudio: Cannot open file '" << fname << "' (errno=" << errno
<<")\n";
return 1;
}
-------------<snip>-------------------------
error message: maudio: Cannot open file './KDE_Startup.wav' (errno=12) =
ERNOMEM
I have looked and added some founded trace:
fopen calls _fopen_r which calls _sfp(), which calls _sfmoreglue().
In this function malloc_r(...,364) is called which returns a 0 pointer
(below there is a _malloc_r trace).
at first backtrace:
#0 0x6108503b in __sfmoreglue (d=0x610900a0, n=4)
at ../../../../../src/newlib/libc/stdio/findfp.c:63
#1 0x610850bd in __sfp (d=0x610900a0)
at ../../../../../src/newlib/libc/stdio/findfp.c:93
#2 0x6107b106 in _fopen_r (ptr=0x610900a0,
file=0x248fda4 "./KDE_Startup.wav", mode=0x402821 "r")
at ../../../../../src/newlib/libc/stdio/fopen.c:135
#3 0x6107b1b4 in fopen (file=0x248fda4 "./KDE_Startup.wav", mode=0x402821
"r")
at ../../../../../src/newlib/libc/stdio/fopen.c:170
#4 0x00402aa2 in AudioSample::setFilename (this=0x1a512618,
fname=0x248fda4 "./KDE_Startup.wav") at sample.cpp:111
#5 0x00401d46 in main (argc=3 '\003', argv=0x1a0265ec) at maudio.cpp:211
#6 0x61003aca in dll_crt0_1 () at
../../../../src/winsup/cygwin/dcrt0.cc:859
#7 0x61003c9d in _dll_crt0 () at ../../../../src/winsup/cygwin/dcrt0.cc:925
#8 0x61003cdc in dll_crt0 (uptr=0x0)
at ../../../../src/winsup/cygwin/dcrt0.cc:937
#9 0x00410c3f in cygwin_crt0 ()
at ../../../../src/winsup/cygwin/lib/cygwin_crt0.c:33
---------------------------------------
below there is the source
-----------------------------------------------------------------
FILE *
_DEFUN (_fopen_r, (ptr, file, mode),
struct _reent *ptr _AND
_CONST char *file _AND
_CONST char *mode)
{
register FILE *fp;
register int f;
int flags, oflags;
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
return NULL;
if ((fp = __sfp (ptr)) == NULL)
return NULL;
if ((f = _open_r (fp->_data, file, oflags, 0666)) < 0)
{
fp->_flags = 0; /* release */
return NULL;
}
----------------------------------------------------------------------------
-
FILE *
__sfp (d)
struct _reent *d;
{
FILE *fp;
int n;
struct _glue *g;
if (!d->__sdidinit)
__sinit (d);
for (g = &d->__sglue;; g = g->_next)
{
for (fp = g->_iobs, n = g->_niobs; --n >= 0; fp++)
if (fp->_flags == 0)
goto found;
if (g->_next == NULL &&
(g->_next = __sfmoreglue (d, NDYNAMIC)) == NULL)
break;
}
d->_errno = ENOMEM;
return NULL;
----------------------------------------------------------------------------
struct _glue *
__sfmoreglue (d, n)
struct _reent *d;
register int n;
{
struct _glue *g;
FILE *p;
g = (struct _glue *) _malloc_r (d, sizeof (*g) + n * sizeof (FILE));
if (g == NULL)
return NULL;
p = (FILE *) (g + 1);
g->_next = NULL;
g->_niobs = n;
g->_iobs = p;
memset (p, 0, n * sizeof (FILE));
return g;
}
----------------------------------------------------------------
(gdb) n
_malloc_r (reent_ptr=0x610900a0, bytes=364)
at ../../../../../src/newlib/libc/stdlib/mallocr.c:2325
2325 INTERNAL_SIZE_T nb = request2size(bytes); /* padded request
size; */
2327 MALLOC_LOCK;
2331 if (is_small_request(nb)) /* Faster version for small requests */
2333 idx = smallbin_index(nb);
2337 q = bin_at(idx);
2338 victim = last(q);
2342 if (victim == q)
2344 q = next_bin(q);
2345 victim = last(q);
2348 if (victim != q)
2358 idx += 2; /* Set for bin scan below. We've already scanned 2
bins. */
2360 }
2393 if ( (victim = last_remainder->fd) != last_remainder)
2430 if ( (block = idx2binblock(idx)) <= binblocks)
2530 remainder_size = long_sub_size_t(chunksize(top), nb);
2531 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
2545 malloc_extend_top(RCALL nb);
2546 remainder_size = long_sub_size_t(chunksize(top), nb);
2547 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
2546 remainder_size = long_sub_size_t(chunksize(top), nb);
2547 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
2549 MALLOC_UNLOCK;
2550 return 0; /* propagate failure */
trace again with var printing
(gdb) n
_malloc_r (reent_ptr=0x610900a0, bytes=364)
at ../../../../../src/newlib/libc/stdlib/mallocr.c:2325
2325 INTERNAL_SIZE_T nb = request2size(bytes); /* padded request
size; */
(gdb)
2327 MALLOC_LOCK;
3: remainder_size = 1627979936
2: nb = 368
(gdb)
2331 if (is_small_request(nb)) /* Faster version for small requests */
3: remainder_size = 1
2: nb = 368
(gdb)
2333 idx = smallbin_index(nb);
3: remainder_size = 1
2: nb = 368
(gdb)
2337 q = bin_at(idx);
3: remainder_size = 368
2: nb = 368
(gdb) p idx
$6 = 46
(gdb) n
2338 victim = last(q);
3: remainder_size = 368
2: nb = 368
(gdb) p q
$7 = 0x61091c38
(gdb) n
2342 if (victim == q)
3: remainder_size = 368
2: nb = 368
(gdb) p victim
$8 = 0x61091c38
(gdb) n
2344 q = next_bin(q);
3: remainder_size = 368
2: nb = 368
(gdb)
2345 victim = last(q);
3: remainder_size = 368
2: nb = 368
(gdb) display q
4: q = 0x61091c40
(gdb) n
2348 if (victim != q)
4: q = 0x61091c40
3: remainder_size = 368
2: nb = 368
(gdb)
2358 idx += 2; /* Set for bin scan below. We've already scanned 2
bins. */
4: q = 0x61091c40
3: remainder_size = 368
2: nb = 368
(gdb) display idx
5: idx = 46
(gdb) n
2360 }
5: idx = 48
4: q = 0x61091c40
3: remainder_size = 368
2: nb = 368
(gdb)
2393 if ( (victim = last_remainder->fd) != last_remainder)
5: idx = 48
4: q = 0x61091c40
3: remainder_size = 368
2: nb = 368
(gdb) display victim
6: victim = 0x61091c40
(gdb) display last_remainder
No symbol "last_remainder" in current context.
(gdb) n
2430 if ( (block = idx2binblock(idx)) <= binblocks)
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x61091c40
3: remainder_size = 368
2: nb = 368
(gdb)
2530 remainder_size = long_sub_size_t(chunksize(top), nb);
6: victim = 0x61091ad0
5: idx = 48
4: q = 0xc
3: remainder_size = 0
2: nb = 368
(gdb)
2531 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
6: victim = 0x61091ad0
5: idx = 48
4: q = 0xc
3: remainder_size = -368
2: nb = 368
(gdb) n
2545 malloc_extend_top(RCALL nb);
6: victim = 0x61091ad0
5: idx = 48
4: q = 0xc
3: remainder_size = -368
2: nb = 368
(gdb)
2546 remainder_size = long_sub_size_t(chunksize(top), nb);
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x1a552000
3: remainder_size = 8193
2: nb = 368
(gdb)
2547 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x1a552000
3: remainder_size = 8193
2: nb = 368
(gdb)
2546 remainder_size = long_sub_size_t(chunksize(top), nb);
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x1a552000
3: remainder_size = 8193
2: nb = 368
(gdb)
2547 if (chunksize(top) < nb || remainder_size < (long)MINSIZE)
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x1a552000
3: remainder_size = -368
2: nb = 368
(gdb)
2549 MALLOC_UNLOCK;
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x1a552000
3: remainder_size = -368
2: nb = 368
(gdb)
2550 return 0; /* propagate failure */
6: victim = 0x61091ad0
5: idx = 48
4: q = 0x61095a9c
3: remainder_size = 0
2: nb = 368
Does anyone have an idea whats going wrong ??
Regards
Ralf Habacker
EMail: Ralf AT habacker DOT de
Ralf DOT Habacker AT saght DOT tessag DOT com
- Raw text -