From owner-freebsd-hackers@FreeBSD.ORG Thu Jul 31 21:44:17 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9A63737B401 for ; Thu, 31 Jul 2003 21:44:17 -0700 (PDT) Received: from whale.sunbay.crimea.ua (whale.sunbay.crimea.ua [212.110.138.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8D50443F85 for ; Thu, 31 Jul 2003 21:44:11 -0700 (PDT) (envelope-from ru@sunbay.com) Received: from whale.sunbay.crimea.ua (ru@localhost [127.0.0.1]) h714i40U058873 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 1 Aug 2003 07:44:06 +0300 (EEST) (envelope-from ru@sunbay.com) Received: (from ru@localhost) by whale.sunbay.crimea.ua (8.12.9/8.12.8/Submit) id h714i20a058864; Fri, 1 Aug 2003 07:44:02 +0300 (EEST) (envelope-from ru) Date: Fri, 1 Aug 2003 07:44:02 +0300 From: Ruslan Ermilov To: Ryan Sommers Message-ID: <20030801044402.GF51362@sunbay.com> References: <20030731201227.28952.qmail@neuroflux.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="27ZtN5FSuKKSZcBU" Content-Disposition: inline In-Reply-To: <20030731201227.28952.qmail@neuroflux.com> User-Agent: Mutt/1.5.4i cc: freebsd-hackers@freebsd.org Subject: Re: Assembly Syscall Question X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Aug 2003 04:44:17 -0000 --27ZtN5FSuKKSZcBU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Jul 31, 2003 at 04:12:27PM -0400, Ryan Sommers wrote: > When making a system call to the kernel why is it necessary to push the= =20 > syscall value onto the stack when you don't call another function?=20 >=20 > Example:=20 >=20 > access.the.bsd.kernel: > int 80h > ret=20 >=20 > func: > mov eax, 4 ; Write > call access.the.bsd.kernel > ; End=20 >=20 > Works. However: > func: > mov eax, 4 ; Write > int 80h > ; End=20 >=20 > Doesn't.=20 >=20 This is because in a C library, all system calls are wrapped into C functions, so the stack looks like this when in the syscall code in libc: return address to a program syscall args So the kernel knows how to account for a return address to access actual arguments. So when calling the kernel directly (not through a C library wrapper function), we need to align the stack to fake the kernel we're calling it from the syscall code in libc. Cheers, --=20 Ruslan Ermilov Sysadmin and DBA, ru@sunbay.com Sunbay Software Ltd, ru@FreeBSD.org FreeBSD committer --27ZtN5FSuKKSZcBU Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (FreeBSD) iD8DBQE/KfASUkv4P6juNwoRAuIvAJwIS+xiURcx7EdKRUchHkmy16S+EwCgh+zt lwh9Xx+OmiYK5tqCbXZqfEI= =3Uw8 -----END PGP SIGNATURE----- --27ZtN5FSuKKSZcBU--