Skip to contentSkip to conversation

USE_CODE_COPY breaks clone

Qemu-devel Rafael Ávila de Espíndola 1 participant 2 messages Sep 1, 2004

lore
Share & tools
lore
#0 lore raw

The cvs version of qemu (i386->i386) generates a segmentation fault in the emulated code of the attached test program. Commenting the definition of USE_CODE_COPY make the test execute successfully.

I think that the problem is in the fact that cpu_init is called in the parent process and this functions calls modify_ldt.

Where can I found some documentation about modify_ldt? What is USE_CODE_COPY supposed to do?

I will try to call cpu_init from within the new thread and see if it works.

One more question: What do you think about breaking the do_fork function in do_fork, do_clone and do_vfork? Presently it tries to guess if it should call fork or clone, but do_syscall knows the answer :)

Thanks for any comment,
Rafael

#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

int f(void *oie) {
    printf("%s\n",(char *)oie);
    return 0;
}
int main() {
    const int stack_size = 8192;
    int ret;
    void *buf = malloc(stack_size);
    void *buff_end = buf + stack_size;
    unsigned int flags =CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND;
    char msg[] = "tata";
    ret = clone(f, buff_end, flags, (void *) msg);
    assert(ret != -1);
    printf("blit\n");
    return 0;
}
#1 lore raw
Quoted 5 lines · Rafael Ávila de Espíndola

I think that the problem is in the fact that cpu_init is called in the parent process and this functions calls modify_ldt.

Where can I found some documentation about modify_ldt? What is USE_CODE_COPY supposed to do?

Ok. It translate i386 to i386 code by copying it.

Quoted 1 line

I will try to call cpu_init from within the new thread and see if it works.

No it doesn't. If clone is called with CLONE_VM then the kernel does mm = oldmm;
and both processes share the ldt. So the parent ldt is "also" changed when cpu_init is called from clone_func.

I could not find out why it is necessary to modify the ltd of the process for code copy to work. Is there some documentation? Could someone explain?

Does someone have an Idea of how to solve this?

Thanks,
Rafael