Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsjail/kafel for other architectures #52

Closed
ebadi opened this issue Oct 14, 2017 · 8 comments
Closed

nsjail/kafel for other architectures #52

ebadi opened this issue Oct 14, 2017 · 8 comments

Comments

@ebadi
Copy link
Contributor

ebadi commented Oct 14, 2017

I'm trying to cross compile nsjail for running it on OpenWRT/LEDE and I ended up with unsupported architecture error from Kafel:
https://travis-ci.org/openwrt/packages/builds/282223552#L2385
I found this instructive commit by @rlc2 for adding a new architecture to kafel:
google/kafel@47cfef4
I tried to follow a similar method by creating a template with all (possible) syscall prototypes with the TEMPLATE_NUM as the placeholder for the syscall number. I fixed names for few syscalls by finding the variation of the syscall name in other architecture and adding them to the template. (e.g adding newX, _X, X2 for syscall X) but what are we supposed to do with the syscalls that unique to the architecture. Can we simply ignore them?

python3 parser.py 
Syscall not found in the template: cachectl
Syscall not found in the template: cacheflush
Syscall not found in the template: pkey_alloc
Syscall not found in the template: pkey_free
Syscall not found in the template: pkey_mprotect
Syscall not found in the template: statx
Syscall not found in the template: sysmips
Syscall not found in the template: timerfd

Please also take a look at these files if my explanations are not clear:
https://github.com/ebadi/syscalls-table/blob/master/mips64_syscalls.c
https://github.com/ebadi/syscalls-table/blob/master/template_syscalls.c

@robertswiecki
Copy link
Collaborator

Hm.. the whole syscall table is architecture-specific, I don't think these should be ignored, but simply added to the array?

{"sysmips",
 4149 ,
 NORMAL,
 {
         [ARG_0] = .....
 }},

Or, am I misunderstanding here? If you did mips syscall table on the basis of aarch64 or some other syscall table, then the way to go is to simply add them (at the end, or sorted, I guess it doesn't matter). We don't have any canonical syscall tables.

@ebadi
Copy link
Contributor Author

ebadi commented Oct 14, 2017

I was (still am) a bit confused about few differences between naming in this table and the one used in the nsjail. Which one is correct ? or does it even matter!?
I will send a pull request soon, but please be critical about it and check it properly before merge ;) as I only have a little experience with these details. :)
Thanks

@ebadi
Copy link
Contributor Author

ebadi commented Oct 15, 2017

I just noticed that my method will not work as the size of input arguments for the same syscall is different in different architectures:
accept4 in arm_syscall.c

    {"accept4",
     366,
     NORMAL,
     {
             [ARG_0] = {"fd", 4}, [ARG_1] = {"upeer_sockaddr", 4},
             [ARG_2] = {"upeer_addrlen", 4}, [ARG_3] = {"flags", 4},
     }},

accept4 in amd64_syscall.c

    {"accept4",
     288,
     NORMAL,
     {
             [ARG_0] = {"fd", 4}, [ARG_1] = {"upeer_sockaddr", 8},
             [ARG_2] = {"upeer_addrlen", 8}, [ARG_3] = {"flags", 4},
     }},

I also noticed that some syscalls that are available on all architecture are missing in kafel such as statx and pkey_mprotect. Please take a look at this: https://fedora.juszkiewicz.com.pl/syscalls.html

@robertswiecki
Copy link
Collaborator

Here's import for aarch64 - google/kafel@2ae8e11

But generally, yes, argument sizes might be different between architectures - but generally the same for the same size of bitness, so it should be technically ok to use existing arm template for mips32 syscalls, and aarch64 template for mips64 sysacalls. The argument sizes are typically the same (e.g. integers, masks), just things like addresses have different bitness.

@robertswiecki
Copy link
Collaborator

In other words, if you're trying to create syscall table for mips32, please use arm_syscall template, if for mips64 please try to use aarch64 template. Then please try to remove syscalls which are not present in mips, and add syscalls which are specific to mips.

@ebadi
Copy link
Contributor Author

ebadi commented Oct 23, 2017

The number of undefined syscalls in the templates are high. I should think about a better solution to generate this list!
https://github.com/ebadi/syscalls-table/blob/master/parser.py

python3 parser.py 32 mipso32
Syscall found: 294
Syscall not found 63
python3 parser.py 64 mips64
Syscall found: 239
Syscall not found 85

@robertswiecki
Copy link
Collaborator

What about manually checking (at least some rudumentaty check) with

https://github.com/torvalds/linux/blob/master/arch/mips/kernel/scall64-64.S

and

https://github.com/torvalds/linux/blob/master/arch/mips/kernel/scall32-o32.S

Given that we don't have tables for mips yet, I think we could marge your tables as-is, given that it passes this rudimentary/manual check (total number of syscalls, a few examples of syscalls and their numbers in your table), and fix any eventual problems later on?

@ebadi
Copy link
Contributor Author

ebadi commented Oct 25, 2017

I cleaned up my code here and did a quick check to make sure that syscall numbers match with the links you provided. Please take a look at the result

@ebadi ebadi closed this as completed Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants