From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: oops? read/write vs type of length parameter Date: Wed, 13 Apr 2011 13:02:18 -0700 Organization: UCLA Computer Science Department Message-ID: <4DA6014A.9030402@cs.ucla.edu> References: <87wrj1jhfc.fsf@rho.meyering.net> <87hba5yq0p.fsf@uwakimon.sk.tsukuba.ac.jp> <834o64sxd7.fsf@gnu.org> <4DA3A7F8.1020503@cs.ucla.edu> <83k4f0qijz.fsf@gnu.org> <4DA3DDCD.10700@cs.ucla.edu> <4DA40AFE.8050406@cs.ucla.edu> <4DA47581.9010509@cs.ucla.edu> <4DA53148.5000903@cs.ucla.edu> <4DA55B85.5090305@cs.ucla.edu> <4DA5C9F6.3070209@cs.ucla.edu> <83bp0aqd6k.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1302724952 25898 80.91.229.12 (13 Apr 2011 20:02:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 13 Apr 2011 20:02:32 +0000 (UTC) Cc: jim@meyering.net, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 13 22:02:27 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QA6Gh-0000BK-HR for ged-emacs-devel@m.gmane.org; Wed, 13 Apr 2011 22:02:27 +0200 Original-Received: from localhost ([::1]:34985 helo=lists2.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QA6Gg-0006ae-Rk for ged-emacs-devel@m.gmane.org; Wed, 13 Apr 2011 16:02:26 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QA6Gd-0006aZ-FV for emacs-devel@gnu.org; Wed, 13 Apr 2011 16:02:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QA6Gc-0006Np-DG for emacs-devel@gnu.org; Wed, 13 Apr 2011 16:02:23 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:51941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QA6Ga-0006NV-Ig; Wed, 13 Apr 2011 16:02:20 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 4EC1939E80DB; Wed, 13 Apr 2011 13:02:19 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2PucnXgCtybo; Wed, 13 Apr 2011 13:02:18 -0700 (PDT) Original-Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 7B2A939E8083; Wed, 13 Apr 2011 13:02:18 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Thunderbird/3.1.9 In-Reply-To: <83bp0aqd6k.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:138466 Archived-At: On 04/12/2011 11:37 PM, Eli Zaretskii wrote: > We cannot assume that a given hardware device is 64-bit- and > signedness-clean as it should be. That's true, and it's independent of the other issues that we're discussing. And it comes up with all I/O, not just writes to sound devices, so it should be fixed in emacs_write (and emacs_read), independently of the other changes. This is the MAX_RW_COUNT issue I mentioned in . Here's a simple patch which fixes the problem. A platform that is known not to have the bug can "#define MAX_RW_COUNT SIZE_MAX". * sysdep.c (MAX_RW_COUNT): New macro, to work around kernel bugs. (emacs_read, emacs_write): Use it. === modified file 'src/sysdep.c' --- src/sysdep.c 2011-04-13 05:02:54 +0000 +++ src/sysdep.c 2011-04-13 19:52:07 +0000 @@ -1825,6 +1825,17 @@ return rtnval; } +/* Maximum number of bytes to read or write in a single system call. + This works around a serious bug in Linux kernels before 2.6.16; see + . + It's likely to work around similar bugs in other operating systems, so do it + on all platforms. Round INT_MAX down to a page size, with the conservative + assumption that page sizes are at most 2**18 bytes (any kernel with a + page size larger than that shouldn't have the bug). */ +#ifndef MAX_RW_COUNT +#define MAX_RW_COUNT (INT_MAX >> 18 << 18) +#endif + /* Read from FILEDESC to a buffer BUF with size NBYTE, retrying if interrupted. Return the number of bytes read, which might be less than NBYTE. On error, set errno and return -1. */ @@ -1833,7 +1844,7 @@ { register ssize_t rtnval; - while ((rtnval = read (fildes, buf, nbyte)) == -1 + while ((rtnval = read (fildes, buf, min (nbyte, MAX_RW_COUNT))) == -1 && (errno == EINTR)) QUIT; return (rtnval); @@ -1852,7 +1863,7 @@ while (nbyte > 0) { - rtnval = write (fildes, buf, nbyte); + rtnval = write (fildes, buf, min (nbyte, MAX_RW_COUNT)); if (rtnval < 0) {