syscall

Garrett Cooper gcooper at FreeBSD.org
Mon Oct 18 12:08:39 UTC 2010


On Mon, Oct 18, 2010 at 4:32 AM, Eugene Grosbein <eugen at grosbein.pp.ru> wrote:
> On 18.10.2010 18:11, Kostik Belousov wrote:
>> On Mon, Oct 18, 2010 at 05:27:21PM +0700, Eugene Grosbein wrote:
>>> Hi!
>>>
>>> I've written an utility in C that does not link libc normally,
>>> instead it includes <sys/syscall.h> and calls syscall().
>>> It works nice for FreeBSD8/i386.
>>>
>>> Now I'm porting it to FreeBSD8/amd64 and just cannot find
>>> how to call syscall() directly from C code.
>> Show what you tried to do. Syscall() at the C-level works the same
>> (well, almost, but the differences are too subtle for this discussion)
>> for all architectures.
>
> I'm prepearing a binary that would start before /sbin/init
> to make just a couple of ioctl(MDIOCATTACH)/nmount system calls
> then execve(/sbin/init). It has to be small in size for NanoBSD build.
> Detailed explanation (in russian) and source code are available here:
> http://dadv.livejournal.com/105161.html
>
> In short:
>
> #include <sys/syscall.h>
>
> #define MESG    "Hello, world!\n"
> #define MESG_SZ sizeof(MESG)-1
>
> int syscall(const int n, ...);
>
> #define _exit(a)       syscall(SYS_exit, a)
> #define write(a, b, c) syscall(SYS_write, a, b, c)
>
> int errno;
>
> int main() {
>  write(1,MESG,MESG_SZ);
>  _exit(0);
>  return 0; /* make compiler happy */
> }
>
>>> For arm, i386 and mips there are:
>>>
>>> lib/libc/arm/sys/syscall.S
>>> lib/libc/i386/sys/syscall.S
>>> lib/libc/mips/sys/syscall.S
>> amd64 syscall() wrapper code is autogenerated.
>>
>>>
>>> What about amd64?
>> Indeed, what is your issue with amd64 ?
>
> I cannot find a module to link with
> to resolve syscall() symbol when I do not want to link with libc.

    Official work similar to this was just committed yesterday at SVN r214006.
Cheers,
-Garrett


More information about the freebsd-hackers mailing list