Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive

[WIP] Add system call bindings#1984

Closed
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:add-syscalls
Closed

[WIP] Add system call bindings#1984
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:add-syscalls

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Dec 6, 2017

So I was just looking at @Darredevil's upcoming fiber library and realized that I had this branch lying here for quite a while (almost a year now).

One way to do system calls is by using syscall from libc, another is the obvious by defining the assembler directly as e.g. https://github.com/kubo39/syscall-d does.
Let me know which approach you prefer, but I think adding the syscall numbers can be done in any case.
We have used this approach for mir-random.

See also:

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

@dlang-bot dlang-bot added the WIP Work In Progress - not ready for review or pulling label Dec 6, 2017
char* getpass(const(char)* prompt);

// linux system call number from Linux's asm/unistd.h
version(X86)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this corresponds to 30x file size :-). Could we add this as a another module and publicly import it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which file do you suggest?
I put them in this file, because that's where they are defined on Linux.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, perhaps core.sys.linux.syscalls. I don't have a good answer, and maybe they could go here, indeed.

// linux system call number from Linux's asm/unistd.h
version(X86)
{
enum SYS_restart_syscall = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum SYS: clong { restart_syscall = 0; ... } is a bit too much (for the C's API)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this as well! I just wasn't sure about this and there seemed to be a couple of old precedents on SYS_ when I did this (one year ago).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fair to use enums here, but that's just my preference. It's easy to generate global enums from it at ctfe anyway, if it's required.

@Darredevil
Copy link
Contributor

LGTM
Looking forward to not having to define each syscall by hand when I need it.

@wilzbach
Copy link
Contributor Author

enum SYS: clong { restart_syscall = 0; ... } is a bit too much (for the C's API)?

Done.

I'm not sure, perhaps core.sys.linux.syscalls. I don't have a good answer, and maybe they could go here, indeed.

Done. As core/sys/linux/unistd.d isn't part of the documentation build, I didn't include syscalls.d into the documentation build for now.

BTW I also realized that after I added the getRandom syscall to mir, someone opened an issue about them missing on Arm. Hence, the mir people created https://github.com/libmir/mir-linux-kernel which generates syscall numbers headers for all Linux architectures.
Is this an issue for us? Should this PR also include syscall numbers for other architectures or should we keep it light for now & move step by step?

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carun
Copy link
Contributor

carun commented Oct 6, 2019

Wow! It has been 1.5 years since this PR was raised.

What is blocking this PR at the moment? I need the syscalls for gettid to use in std.experimental.logger. See dlang/phobos#6978

@carun
Copy link
Contributor

carun commented Oct 6, 2019

@wilzbach there are conflicts. Do you mind rebasing the branch add-syscalls on master?

@carun
Copy link
Contributor

carun commented Oct 6, 2019

@wilzbach just wondering, don't you need to add an entry in mak/SRCS as well?

@carun
Copy link
Contributor

carun commented Oct 6, 2019

ping @MartinNowak @Burgos

@wilzbach
Copy link
Contributor Author

wilzbach commented Oct 6, 2019

Sorry, but I won't be working on this in the forseeable future. Feel free to adopt this PR though.

@wilzbach wilzbach added the Orphaned The author of the PR is no longer available and this PR can be adopted by anyone. label Oct 6, 2019
@wilzbach wilzbach added the Phantom Zone Has value/information for future work, but closed for now label Oct 6, 2019
@wilzbach
Copy link
Contributor Author

wilzbach commented Oct 6, 2019

For future readers, I advise them to use the mir-linux-kernel package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Orphaned The author of the PR is no longer available and this PR can be adopted by anyone. Phantom Zone Has value/information for future work, but closed for now

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants