[PATCH v2 22/46] vfork: Use fork if arch does not have the vfork syscall

Markos Chandras markos.chandras at gmail.com
Tue Nov 27 09:36:42 UTC 2012


On 27 November 2012 09:02, Vineet Gupta <Vineet.Gupta1 at synopsys.com> wrote:
> On Tuesday 27 November 2012 02:09 PM, Vineet Gupta wrote:
>> On Monday 26 November 2012 07:54 PM, Markos Chandras wrote:
>>> From: Markos Chandras <markos.chandras at imgtec.com>
>>>
>>> Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
>>> ---
>>>  libc/sysdeps/linux/common/vfork.c | 16 +++++++++++++++-
>>>  1 file changed, 15 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/libc/sysdeps/linux/common/vfork.c b/libc/sysdeps/linux/common/vfork.c
>>> index e7c9208..377418c 100644
>>> --- a/libc/sysdeps/linux/common/vfork.c
>>> +++ b/libc/sysdeps/linux/common/vfork.c
>>> @@ -4,13 +4,27 @@
>>>   * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
>>>   */
>>>
>>> +#include <signal.h>
>>>  #include <unistd.h>
>>>  #include <sys/types.h>
>>>  #include <sys/syscall.h>
>>>
>>>  extern __typeof(vfork) __vfork attribute_hidden;
>>>
>>> -#ifdef __NR_vfork
>>> +#if defined(__NR_fork) && !defined(__NR_vfork)
>>> +pid_t __vfork(void)
>>> +{
>>> +    pid_t pid = INLINE_SYSCALL(fork, 0);
>>> +
>>> +    if (pid<0)
>>> +            return -1
>>> +
>>> +    return pid;
>>> +}
>>> +weak_alias(__vfork, vfork)
>>> +libc_hidden_weak(vfork)
>>> +
>>> +#elif defined(__NR_vfork)
>>>
>>>  # define __NR___vfork __NR_vfork
>>>  _syscall0(pid_t, __vfork)
>>>
>>
>> Hi Markos,
>>
>> First of all many thanks for picking this up. I'm the maintainer for ARC
>> Linux kernel - current being reviewed on lkml (along side metag) so your
>> work will help us immensely - as we also need to have asm-generic
>> unistd.h based syscall ABI.
>>
>> In that regarding I've been looking at your v1 and v2 patches and would
>> like to contribute as much as possible.
>>
>> While v1 of this particular patch made sense to me - this one doesn't.
>> kernel's asm-generic unistd.h only defines clone (and doesn't define
>> vfork/fork). Thus this file will compile to nothing as opposed to v1
>> where vfork would correctly call clone syscall with correct args -
>> something which the vfork syscall handler itself in kernel typically
>> does. And since that would be gone - we need to do same thing in user
>> space wrapper.
>>
>> What am I missing here...
>>
>> Thx,
>> -Vineet
>
> Spoke too soon - I went back to the your orig change and it's review
> comment - so the file compiling to NOP is indeed good. Please ignore above.

Hi Vineet,

Thanks for the comments. Yes that is correct. But if I understand it
correctly, if an arch uses NPTL, it is possible to pick the nptl
implementation for vfork. See the following snippet from
libc/sysdeps/linux/common/Makefile.in

ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
CSRC- += fork.c getpid.c raise.c openat.c close.c read.c write.c
CSRC- += $(if $(findstring =arm=,=$(TARGET_ARCH)=),vfork.c)
CSRC- += $(if $(findstring =x86_64=,=$(TARGET_ARCH)=),vfork.c)
...
endif

-- 
Regards,
Markos


More information about the uClibc mailing list