public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* How can I declare a global variable related to syscall routines without any issue?
@ 2019-12-30  0:19 Bbbb Im
  2019-12-30  2:20 ` Paul Pluzhnikov via libc-help
  2019-12-30 11:34 ` Florian Weimer
  0 siblings, 2 replies; 4+ messages in thread
From: Bbbb Im @ 2019-12-30  0:19 UTC (permalink / raw)
  To: libc-help

Hi

I am trying to modify x86-64 syscall routines to behave conditionally by a
flag variable. To do that, I added simple if statements in the
internal_syscall macros to check the value of the flag.
However, since they are macros, I need to declare the flag variable as a
global variable somewhere, then add "extern int" declaration in all C files
which call syscalll macros, and the object code which has the declaration
should be linked to all the objs with "extern" statements.
The problem is that which C file is the best place to declare the flag as a
global variable that does not break anything and linked to all the sycall
related C files? I could modify makefiles to link the declared obj files to
be linked to all others, but I am not sure it's the correct way to do it.

Thank you.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How can I declare a global variable related to syscall routines without any issue?
  2019-12-30  0:19 How can I declare a global variable related to syscall routines without any issue? Bbbb Im
@ 2019-12-30  2:20 ` Paul Pluzhnikov via libc-help
  2019-12-30  2:31   ` Bbbb Im
  2019-12-30 11:34 ` Florian Weimer
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Pluzhnikov via libc-help @ 2019-12-30  2:20 UTC (permalink / raw)
  To: Bbbb Im; +Cc: libc-help

On Sun, Dec 29, 2019 at 4:19 PM Bbbb Im <bjspam.im@gmail.com> wrote:
>
> Hi
>
> I am trying to modify x86-64 syscall routines to behave conditionally by a
> flag variable.

What are you trying to achieve?
See also http://xyproblem.info/

>  To do that, I added simple if statements in the
> internal_syscall macros to check the value of the flag.
> However, since they are macros, I need to declare the flag variable as a
> global variable somewhere, then add "extern int" declaration in all C files
> which call syscalll macros, and the object code which has the declaration
> should be linked to all the objs with "extern" statements.
> The problem is that which C file is the best place to declare the flag as a
> global variable that does not break anything and linked to all the sycall
> related C files? I could modify makefiles to link the declared obj files to
> be linked to all others, but I am not sure it's the correct way to do it.
>
> Thank you.



-- 
Paul Pluzhnikov

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How can I declare a global variable related to syscall routines without any issue?
  2019-12-30  2:20 ` Paul Pluzhnikov via libc-help
@ 2019-12-30  2:31   ` Bbbb Im
  0 siblings, 0 replies; 4+ messages in thread
From: Bbbb Im @ 2019-12-30  2:31 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: libc-help

Simply, I want, on some occasions, something else should be executed rather
than the original syscall instruction.

For example, in sysdeps/unix/sysv/linux/x86_64/sysdep.h;

#define internal_syscall0(number, err, dummy...) \
({ \
    unsigned long int resultvar; \
    if (!my_flag) {                                                    \
        asm volatile ( \
        "syscall\n\t" \
        : "=a" (resultvar) \
        : "0" (number) \
        : "memory", REGISTERS_CLOBBERED_BY_SYSCALL); \
    } else {                                                            \
        asm volatile ( \
        something else here .... );                             \
    }                                                                   \
    (long int) resultvar; \
})

I want 'my_flag' is set/unset by my newly created API and any syscalls
should be altered by those "something else here" thing.

Thank you.


2019년 12월 29일 (일) 오후 8:20, Paul Pluzhnikov <ppluzhnikov@google.com>님이 작성:

> On Sun, Dec 29, 2019 at 4:19 PM Bbbb Im <bjspam.im@gmail.com> wrote:
> >
> > Hi
> >
> > I am trying to modify x86-64 syscall routines to behave conditionally by
> a
> > flag variable.
>
> What are you trying to achieve?
> See also http://xyproblem.info/
>
> >  To do that, I added simple if statements in the
> > internal_syscall macros to check the value of the flag.
> > However, since they are macros, I need to declare the flag variable as a
> > global variable somewhere, then add "extern int" declaration in all C
> files
> > which call syscalll macros, and the object code which has the declaration
> > should be linked to all the objs with "extern" statements.
> > The problem is that which C file is the best place to declare the flag
> as a
> > global variable that does not break anything and linked to all the sycall
> > related C files? I could modify makefiles to link the declared obj files
> to
> > be linked to all others, but I am not sure it's the correct way to do it.
> >
> > Thank you.
>
>
>
> --
> Paul Pluzhnikov
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How can I declare a global variable related to syscall routines without any issue?
  2019-12-30  0:19 How can I declare a global variable related to syscall routines without any issue? Bbbb Im
  2019-12-30  2:20 ` Paul Pluzhnikov via libc-help
@ 2019-12-30 11:34 ` Florian Weimer
  1 sibling, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2019-12-30 11:34 UTC (permalink / raw)
  To: Bbbb Im; +Cc: libc-help

* Bbbb Im:

> The problem is that which C file is the best place to declare the flag as a
> global variable that does not break anything and linked to all the sycall
> related C files?

Such definitions are typically put into sysdep.c, but x86_64 already
has sysdep.S, so you would have to write the definition in assembler,
or add a new C file that is linked in the same way as the existing
sysdep file.

Please also note that some system call wrappers are written in
assembler (and some of them are autogenerated), so if you change the C
macro, that won't affect them.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-30 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-30  0:19 How can I declare a global variable related to syscall routines without any issue? Bbbb Im
2019-12-30  2:20 ` Paul Pluzhnikov via libc-help
2019-12-30  2:31   ` Bbbb Im
2019-12-30 11:34 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).