Dan Nicholson wrote:
> On 3/20/07, Bruce Dubbs <[EMAIL PROTECTED]> wrote:
>> I've been trying to figure out why the attached file fails on my LFS
>> systems. It does not fail on FC or RHEL kernels.
>>
>> I'd appreciate it if some of you could run the attached program ans send
>> me the results.
>
> I got all passes on my system.
>
> $ ./mincore01
> mincore01 1 PASS : expected failure: errno = 22 (Invalid argument)
> mincore01 2 PASS : expected failure: errno = 14 (Bad address)
> mincore01 3 PASS : expected failure: errno = 12 (Cannot allocate memory)
> mincore01 4 PASS : expected failure: errno = 12 (Cannot allocate memory)
>
> This is on linux-2.6.20.1/glibc-2.3.6. I have some of the DIY tweaks
> for the toolchain build.
Thanks Dan. I'm really puzzled about this. I pared the code down to
what I have below. compile with `gcc min.c -o min`.
For me, if I do ./min, I get:
PAGESIZE=4096
global_len=8192
global_pointer=0xb7fda000
alloc=2
Result=0
global_vec: 01 01 01 01 01 01
Which is a FAIL. Bit if I do `./min anything`, I get:
argc=2
PAGESIZE=4096
global_len=8192
global_pointer=0xb7f78000
alloc=2
Result=-1
global_vec: 01 01 00 00 00 00
which is a PASS.
The operation we are testing is mincore which is a direct call to the
kernel. The code is in mm/mincore.c.
Its like something is not getting initialized until the printf is run.
My kernel is 2.6.16.27-lfs62-a. I don't see anything in the config that
would make a difference. It's a mystery to me.
-- Bruce
------------------------------
cat <<EOF > min.c
#include <fcntl.h>
#include <errno.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
static int PAGESIZE;
static char file_name[] = "fooXXXXXX";
static char* global_pointer = NULL;
unsigned char* global_vec = NULL;
static int global_len = 0;
static int file_desc = 0;
int main(int ac, char **av)
{
int i;
char* buf;
unsigned char vect[6] = {0,0,0,0,0,0};
if ( ac > 1 ) printf("argc=%d\n", ac);
PAGESIZE = getpagesize();
/* global_pointer will point to a mmapped area of global_len bytes */
global_len = PAGESIZE*2;
buf = (char*)malloc(global_len);
memset(buf,42,global_len);
/* create a temporary file */
file_desc = mkstemp(file_name);
/* fill the temporary file with two pages of data */
write(file_desc,buf,global_len);
free(buf);
/* map the file in memory */
global_pointer = (char *)mmap(NULL,global_len,
PROT_READ|PROT_WRITE|PROT_EXEC,MAP_SHARED,file_desc,0);
i = mincore((void*)global_pointer, (size_t)(global_len*5), vect);
printf("PAGESIZE=%d\n", PAGESIZE);
printf("global_len=%d\n", global_len);
printf("global_pointer=0x%x\n", (unsigned int)global_pointer);
//printf("global_vec=0x%x\n", (unsigned int)global_vec);
printf("alloc=%d\n", (global_len+PAGESIZE-1) / PAGESIZE );
printf("Result=%d\n", i);
printf("global_vec: %02x %02x %02x %02x %02x %02x\n",
vect[0], vect[1], vect[2], vect[3], vect[4], vect[5]);
}
EOF
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page