Generally, systems provide a library or API that sits between normal programs and the operating system. On Unix-like systems, that API is usually part of an implementation of the C library (libc), such as glibc, that provides wrapper functions for the system calls.In C i can use these wrapper functions to make system calls. How do i make system calls in other languages?


Most of the time your language of choice will provide functions (of some sort) that eventually map to the relevant syscalls. In those cases, just use those and call it a day; no need to consider syscall interfaces at all. In fact, I'd argue that unless you're writing a standard library, there should be no need to consider the lower-level details in the first place. It's not like the days of the original IBM PC, where accessing memory structures directly could dramatically increase performance (and even then it was recognized to be a non-optimal solution, because it severely limited portability).

That said, you can perform direct syscalls in any language that allows you to mimic the expected calling convention. In fact, this is not really any different from any inter-binary calls, including library calls (although with libraries it's usually less of an issue since those are likely to be written to the same calling convention anyway).

The calling convention dictates things like how parameters and return values are passed to and from a called function, and forms one part of the ABI (Application Binary Interface) of a platform. Note that in this case, "platform" is a quite wide term, potentially encompassing both operating system, runtime environment, language, compiler and settings (including source-code-level declarations).

So what you need to do is make your other language make a function call that conforms to the calling convention used and then simply call the appropriate interface. If you're using assembler, that's trivial as you're most likely already doing all parameter and results passing by yourself anyway; if you're using something on the other extreme end of the scale like BASIC or Perl, you'll have a very hard time conforming to a foreign calling convention because the languages pretty much lack the concept.

Exactly how you would write the code to use an alternate (or specific) calling convention depends very much on the language (and likely compiler) in question, and is much too broad to answer generally. And of course, you'd need to know which calling convention to conform to.

| improve this answer | |
  • what do you mean by "mimic the expected calling convention"? plz explain it.. – saurav1405 Jul 18 '14 at 13:49
  • @saurav1405 Did you read the answer in full? I feel it is explained fairly well in the paragraphs following that, and certainly better than can be done in the space of a comment. If you aren't familiar with these concepts, I suggest you just do yourself a favor and simply use the facilities offered by your language and runtime of choice, as suggested in the top paragraph. If there is something in particular you want to know, please be a lot more specific. – user Jul 18 '14 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.