Date: Mon, 18 Oct 2010 18:32:51 +0700 From: Eugene Grosbein <eugen@grosbein.pp.ru> To: Kostik Belousov <kostikbel@gmail.com> Cc: hackers@freebsd.org Subject: Re: syscall Message-ID: <4CBC3063.7000407@grosbein.pp.ru> In-Reply-To: <20101018111131.GE2392@deviant.kiev.zoral.com.ua> References: <4CBC2109.4030303@grosbein.pp.ru> <20101018111131.GE2392@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
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. Eugene Grosbein
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4CBC3063.7000407>