Date: Mon, 18 Oct 2010 04:41:48 -0700 From: Garrett Cooper <gcooper@FreeBSD.org> To: Eugene Grosbein <eugen@grosbein.pp.ru> Cc: Kostik Belousov <kostikbel@gmail.com>, hackers@freebsd.org Subject: Re: syscall Message-ID: <AANLkTinoHKu9NKGJpUTUH9ERkv%2Byy-oDiSxDpsJyW8GB@mail.gmail.com> In-Reply-To: <4CBC3063.7000407@grosbein.pp.ru> References: <4CBC2109.4030303@grosbein.pp.ru> <20101018111131.GE2392@deviant.kiev.zoral.com.ua> <4CBC3063.7000407@grosbein.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Oct 18, 2010 at 4:32 AM, Eugene Grosbein <eugen@grosbein.pp.ru> wro= te: > 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 =A0 =A0"Hello, world!\n" > #define MESG_SZ sizeof(MESG)-1 > > int syscall(const int n, ...); > > #define _exit(a) =A0 =A0 =A0 syscall(SYS_exit, a) > #define write(a, b, c) syscall(SYS_write, a, b, c) > > int errno; > > int main() { > =A0write(1,MESG,MESG_SZ); > =A0_exit(0); > =A0return 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 r2140= 06. Cheers, -Garrett
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinoHKu9NKGJpUTUH9ERkv%2Byy-oDiSxDpsJyW8GB>