All of lore.kernel.org
 help / color / mirror / Atom feed
From: Constantine Gavrilov <constg@qlusters.com>
To: bugs@x86-64.org, linux-kernel@vger.kernel.org
Subject: Re: Fwd: Calling syscalls from x86-64 kernel results in a crash on Opteron machines
Date: Mon, 13 Sep 2004 17:17:18 +0300	[thread overview]
Message-ID: <4145ABEE.5050606@qlusters.com> (raw)
In-Reply-To: <200409131715.27584.anatolya@qlusters.com>

[-- Attachment #1: Type: text/plain, Size: 981 bytes --]

>
>
>Subject: Calling syscalls from x86-64 kernel results in a crash on Opteron machines
>Date: Mon, 13 Sep 2004 17:04:17 +0300
>From: Constantine Gavrilov <constg@qlusters.com>
>To: bugs@x86-64.org, linux-kernel@vger.kernel.org
>
>Hello:
>
>We have a piece of kernel code that calls some system calls in kernel
>context (from a process with mm and a daemonized kernel thread that does
>not have mm). This works fine on IA64 and i386 architectures.
>
..............

>Attached please find a test module that tries to call the umask() (JUST
>TO DEMONSTRATE a problem) via the syscall machanism. Both methods (the
>_syscall1() marco and GLIBC INLINE_SYCALL() were used.
>  
>

I forgot to attach a header file with glibc version of syscall inline 
implementation.

-- 
----------------------------------------
Constantine Gavrilov
Kernel Developer
Qlusters Software Ltd
1 Azrieli Center, Tel-Aviv
Phone: +972-3-6081977
Fax:   +972-3-6081841
----------------------------------------


[-- Attachment #2: gsyscall.h --]
[-- Type: text/plain, Size: 2204 bytes --]

#ifndef _GSYSCALL_H_
#define _GSYSCALL_H_

#define __set_errno(Val) errno = (Val)

#undef INLINE_SYSCALL
#define INLINE_SYSCALL(name, nr, args...) \
  ({									      \
    unsigned long resultvar = INTERNAL_SYSCALL (name, , nr, args);	      \
    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
      {									      \
	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
	resultvar = (unsigned long) -1;					      \
      }									      \
    (long) resultvar; })

#undef INTERNAL_SYSCALL_DECL
#define INTERNAL_SYSCALL_DECL(err) do { } while (0)



#undef INTERNAL_SYSCALL
#define INTERNAL_SYSCALL(name, err, nr, args...) \
  ({									      \
    unsigned long resultvar;						      \
    LOAD_ARGS_##nr (args)						      \
    asm volatile (							      \
    "movq %1, %%rax\n\t"						      \
    "syscall\n\t"							      \
    : "=a" (resultvar)							      \
    : "i" (__NR_##name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");	      \
    (long) resultvar; })

#undef INTERNAL_SYSCALL_ERROR_P
#define INTERNAL_SYSCALL_ERROR_P(val, err) \
  ((unsigned long) (val) >= -4095L)

#undef INTERNAL_SYSCALL_ERRNO
#define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))

#define LOAD_ARGS_0()
#define ASM_ARGS_0

#define LOAD_ARGS_1(a1)					\
  register long int _a1 asm ("rdi") = (long) (a1);	\
  LOAD_ARGS_0 ()
#define ASM_ARGS_1	ASM_ARGS_0, "r" (_a1)

#define LOAD_ARGS_2(a1, a2)				\
  register long int _a2 asm ("rsi") = (long) (a2);	\
  LOAD_ARGS_1 (a1)
#define ASM_ARGS_2	ASM_ARGS_1, "r" (_a2)

#define LOAD_ARGS_3(a1, a2, a3)				\
  register long int _a3 asm ("rdx") = (long) (a3);	\
  LOAD_ARGS_2 (a1, a2)
#define ASM_ARGS_3	ASM_ARGS_2, "r" (_a3)

#define LOAD_ARGS_4(a1, a2, a3, a4)			\
  register long int _a4 asm ("r10") = (long) (a4);	\
  LOAD_ARGS_3 (a1, a2, a3)
#define ASM_ARGS_4	ASM_ARGS_3, "r" (_a4)

#define LOAD_ARGS_5(a1, a2, a3, a4, a5)			\
  register long int _a5 asm ("r8") = (long) (a5);	\
  LOAD_ARGS_4 (a1, a2, a3, a4)
#define ASM_ARGS_5	ASM_ARGS_4, "r" (_a5)

#define LOAD_ARGS_6(a1, a2, a3, a4, a5, a6)		\
  register long int _a6 asm ("r9") = (long) (a6);	\
  LOAD_ARGS_5 (a1, a2, a3, a4, a5)
#define ASM_ARGS_6	ASM_ARGS_5, "r" (_a6)

#endif

       reply	other threads:[~2004-09-13 14:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200409131715.27584.anatolya@qlusters.com>
2004-09-13 14:17 ` Constantine Gavrilov [this message]
2004-09-13 14:42   ` Fwd: Calling syscalls from x86-64 kernel results in a crash on Opteron machines Richard B. Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4145ABEE.5050606@qlusters.com \
    --to=constg@qlusters.com \
    --cc=bugs@x86-64.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.