From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 10 16:32:44 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F12901065678 for ; Tue, 10 Mar 2009 16:32:44 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: from mail-ew0-f166.google.com (mail-ew0-f166.google.com [209.85.219.166]) by mx1.freebsd.org (Postfix) with ESMTP id 5D8038FC1F for ; Tue, 10 Mar 2009 16:32:43 +0000 (UTC) (envelope-from bsd.quest@googlemail.com) Received: by ewy10 with SMTP id 10so1414724ewy.43 for ; Tue, 10 Mar 2009 09:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=cqYGnPQLkzw3FQ1lQ3V3AtpeLSZf32YBav85I+0d26s=; b=qbrWRLRet4uBzyYtvswlf44l0nRovQnDAv3YoPsrizeIL238XZvZrgQG1rEwbaFz4k VMLC0S1LHu817ccwQOoJIrs1KIVvT2tCji4HwpBUIZjr2mIz23W1zpuIZsD3x3NzNRYm gG8Bv8jUljFrUwmBnOOmMLBnEI2nBU/n2P2cQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=bfCV8uXMx8H6fR2iDusqO1wgUXIT59FBNJC8ztweVABwx2uNVJlufz42tMCtcJPu/z fVE3CbXQJ3HHjJV4/6ZiEnm77rkeGKrRTmo4joLU0WCu5CRvYOo7ALYGorn5KX3zHmZZ +/fcG2HJNqI1VNsUgGMvtMQjmHlEhSUOpLsGA= MIME-Version: 1.0 Received: by 10.210.136.10 with SMTP id j10mr552977ebd.52.1236702763331; Tue, 10 Mar 2009 09:32:43 -0700 (PDT) In-Reply-To: <671bb5fc0903100905u7484cd1dp9faefc8bc208a6a6@mail.gmail.com> References: <671bb5fc0903100905u7484cd1dp9faefc8bc208a6a6@mail.gmail.com> Date: Tue, 10 Mar 2009 17:32:43 +0100 Message-ID: <671bb5fc0903100932y71e6c78bq8904224959e24e55@mail.gmail.com> From: Alexej Sokolov To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Fwd: write protection by mmap of /dev/mem doesn't work X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Mar 2009 16:32:45 -0000 Sorry, it was my mistake ! seg fault was by reading of data. To do this should PROT_READ|PROT_WRITE be setted. Now it works! Alexej ---------- Forwarded message ---------- From: Alexej Sokolov Date: 2009/3/10 Subject: write protection by mmap of /dev/mem doesn't work To: freebsd-hackers@freebsd.org hello, How can I mmap some memory regions with PROT_WRITE protection flag ? What i do: /* Open mem device */ if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){ perror("/dev/mem"); exit (1); } then if I try to mmap some memory region with PROT_READ it goes Ok. But by PROT_WRITE it doesn't work: sp = mmap ( 0, MCLBYTES, /* Size of remapped buffer = size of mbuf cluster */ PROT_WRITE, MAP_SHARED, devmem_fd, phys_addr /* Physical addres of packet buffer from descriptor */ ); I get by PROT_WRITE " segmentation fault" What is the problem here ? And question again: How can I do it possible to remapp the kernel memory region to user space process through /dev/mem and give to this user process write permissions to remmaped space ? Thanx