On Mon, Aug 10, 2020 at 8:02 AM Waldemar Kozaczuk <[email protected]>
wrote:

> In more complicated situations when single musl file
> calls syscall() for 2 or more system call types (like stdio/tmpnam.o),
> we cannot have single macro that will solve it like previous patch
> did.
>
> In those cases we fallback to statically inlined functions
> defined for each syscall type. The defined variadic syscall/__syscall
> macro then delegates to relevant inlined function by concatenating
> 'inlined_' and syscall number constant name that is a 1st parameter to a
> macro.
>
> Please note that "__attribute__((always_inline))" guarantees
> that the calls to those functions are indeed inlines and do not incur
> any extra function call overhead as it was checked by disassembling
> tmpnam.o.
>

So is there any downside to this approach? Can't we use *just* this
approach, without that extra  -D thing?
If it worked, and we won't need the "-D" things, we can add the "--include
..." thing to *all* musl source files, instead of picking them out
individually.

Also, please begin syscall_to_function.h with a comment describing what it
does - that it is for compiling
unmodified Musl files.



> Signed-off-by: Waldemar Kozaczuk <[email protected]>
> ---
>  Makefile                   |  3 ++-
>  libc/syscall_to_function.h | 15 +++++++++++++++
>  2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/Makefile b/Makefile
> index f6eb21e0..1a1ef54b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -1508,7 +1508,8 @@ musl += stdio/swprintf.o
>  musl += stdio/swscanf.o
>  musl += stdio/tempnam.o
>  libc += stdio/tmpfile.o
> -libc += stdio/tmpnam.o
> +musl += stdio/tmpnam.o
> +$(out)/musl/src/stdio/tmpnam.o: CFLAGS += -D__OSV_SYS_inline_tmpnam
> --include libc/syscall_to_function.h
>  musl += stdio/ungetc.o
>  musl += stdio/ungetwc.o
>  musl += stdio/vasprintf.o
> diff --git a/libc/syscall_to_function.h b/libc/syscall_to_function.h
> index 68922cbf..a9f9afed 100644
> --- a/libc/syscall_to_function.h
> +++ b/libc/syscall_to_function.h
> @@ -14,6 +14,21 @@
>  #define __syscall(syscall_number, fd, cmd, args) fcntl(fd, cmd, args)
>  #endif
>
> +#ifdef __OSV_SYS_inline_tmpnam
> +#include <time.h>
> +__attribute__((always_inline)) static inline long
> inlined_SYS_clock_gettime(clockid_t c, struct timespec *t, int x)
> +{
> +    return clock_gettime(c, t);
> +}
>

A thought: Do we really need this to be an actual C function - maybe this
can also be a macro?
My thinking is that maybe you can get around the need to specify all these
parameter types for every system call and can just use a macro to copy them.
On the other hand, it's not criticial - there is not a very large number of
system calls, and after you write a dozen of them or so, you'd probably be
done.


+
> +__attribute__((always_inline)) static inline long
> inlined_SYS_access(const char *p, int i)
> +{
> +    return access(p, i);
> +}
> +
> +#define __syscall(sys_number, ...) (inlined_##sys_number(__VA_ARGS__))
> +#endif
> +
>  /*
>  #define syscall(syscall_number, ...) \
>    #if syscall_number == SYS_close \
> --
> 2.25.1
>
> --
> You received this message because you are subscribed to the Google Groups
> "OSv Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/osv-dev/20200810050225.13067-2-jwkozaczuk%40gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/CANEVyjvtDQ7owM9btpTt0fL%3DZwJouGGOwoqnhH73QjCW0xsBDg%40mail.gmail.com.

Reply via email to