From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 2 00:47:55 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 E1A7237B404 for ; Mon, 2 Jun 2003 00:47:55 -0700 (PDT) Received: from milla.ask33.net (milla.ask33.net [217.197.166.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3F15E43FA3 for ; Mon, 2 Jun 2003 00:47:55 -0700 (PDT) (envelope-from nick@milla.ask33.net) Received: by milla.ask33.net (Postfix, from userid 1001) id 618B13ABB47; Mon, 2 Jun 2003 09:53:28 +0200 (CEST) Date: Mon, 2 Jun 2003 09:53:28 +0200 From: Pawel Jakub Dawidek To: freebsd-hackers@freebsd.org Message-ID: <20030602075328.GV45118@garage.freebsd.pl> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="aPbDRKcb5+hBUoJi" Content-Disposition: inline X-PGP-Key-URL: http://garage.freebsd.pl/jules.asc X-OS: FreeBSD 4.8-RELEASE i386 X-URL: http://garage.freebsd.pl User-Agent: Mutt/1.5.1i Subject: Locking, locking... 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: Mon, 02 Jun 2003 07:47:56 -0000 --aPbDRKcb5+hBUoJi Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hello hackers... I need advice how to handle with one locking problem. For example I got some list with some values. This list could be modified by any process. I want to get values from this list and copy them to allocated table. But how to count number of needed fields? mtx_lock(&mtx_list_lock); n =3D 0; SLIST_FOREACH(elem, &list_head, l_next) { n++; } mtx_unlock(&mtx_list_lock); tab =3D malloc(n * sizeof(something), M_TEMP, M_WAITOK); mtx_lock(&mtx_list_lock); [...] As we all knew size of list could be changed when we were in malloc(). Of course we could check list size again after malloc() and mtx_lock(), but what to do when it was changed? Recall memory allocation? If size of this list depends on every process there is a chance to DoS such piece of code. Return an error? Not always it is possible. IMHO there should be malloc() version that could be called under lock. Malloc() M_NOWAIT could be called in such scenario? How do you handle with situations like this? Thanks! --=20 Pawel Jakub Dawidek pawel@dawidek.net UNIX Systems Programmer/Administrator http://garage.freebsd.pl Am I Evil? Yes, I Am! http://cerber.sourceforge.net --aPbDRKcb5+hBUoJi Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.7 (FreeBSD) iQCVAwUBPtsCeD/PhmMH/Mf1AQEilwP+N/Umn+2e4+VFSQisBa6hKpIXfyPFFvoY xnBoJuzBp+clBVn7cgTPHy1TfhWZF4caNcFBcjQLHENvdI/G45pFyXP3Xoe3BSrO bXSTxevhzz7ISBxmjmh20acI3RNY3BdRNuKuXNN4Kob5TdMb1Lp72t3O/txEQCDf DweTa/Buv1g= =RcVv -----END PGP SIGNATURE----- --aPbDRKcb5+hBUoJi--