Stack memory for clone(2)?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello.

I found the following code fails on arm processor,
while it works on x86 processor.
Kernel version is 2.4.31-a9-3 (for Armadillo-9).

--- Code start ---
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <stdlib.h>

static int child(void *arg) {
  _exit(1);
}

int main(int argc, char *argv[]) {
  //char *stack = malloc(1024);
  //const pid_t pid = clone(child, stack + (1024 / 2), CLONE_NEWNS, (void *) argv);
  static char stack[1024];
  const pid_t pid = clone(child, stack + (sizeof(stack) / 2), CLONE_NEWNS, (void *) argv);
  while (waitpid(pid, NULL, __WALL) == EOF && errno == EINTR);
  return 0;
}
--- Code end ---

The __do_user_fault() in arch/arm/mm/fault-common.c is called by clone(2).

--- dmesg start ---
newns: unhandled page fault at pc=0x40007ad4, lr=0x40007aa0 (bad address=0x8c4001ca, code 5)
pc : [<40007ad4>]    lr : [<40007aa0>]    Not tainted
sp : 000107f9  ip : 00000000  fp : 00010885
r10: 4001c6b8  r9 : 0065cf04  r8 : 0001089d
r7 : 00008164  r6 : 00008260  r5 : 00010825  r4 : fffffc44
r3 : 0000006f  r2 : 4001c2fc  r1 : 8c4001ca  r0 : 00000000
Flags: Nzcv  IRQs on  FIQs on  Mode USER_32  Segment user
Control: C000317F  Table: C56EC000  DAC: 00000015
--- dmesg end ---

The above code works if I use malloc(3).
Is passing 'statically' allocated stack memory to clone(2) illegal?

Regards.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux