From patchwork Tue Sep 16 13:31:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov X-Patchwork-Id: 4918021 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C99019F349 for ; Tue, 16 Sep 2014 13:31:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B8C4200F0 for ; Tue, 16 Sep 2014 13:33:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 50D8F200E6 for ; Tue, 16 Sep 2014 13:33:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8E7F76E43B; Tue, 16 Sep 2014 06:33:12 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f181.google.com (mail-we0-f181.google.com [74.125.82.181]) by gabe.freedesktop.org (Postfix) with ESMTP id B6CB16E43A for ; Tue, 16 Sep 2014 06:33:10 -0700 (PDT) Received: by mail-we0-f181.google.com with SMTP id w62so5769960wes.40 for ; Tue, 16 Sep 2014 06:33:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sJTP6lAkmn2XMRcCDnRVMam0VU7+ppJDPfHoChhaqhg=; b=pJWyUFZ0mAGquySGlNkIn2tPFuNiInl0+yNW6I2+F1sAOf1oJfD1XRhO4Bkx61dOrG evp88ldl8HmfzIBaqYUOMW5Zgc/YOUpJtXHpCs2me72EeQLpfKmxJK5AoNbBOHHLFnhz Ajk/bqVk995q6MBzpfWFB2Q5aDNxkTlxBNl6dIAdGZP/bDWERz3yKWfWiDKN8C+W00oO 2wefrf9/Q2o4w0mav1NqMl2LstWo1VRtTgfEJYH/ahrgFLxLMqgLCjo+nRvCeSoOZGxX 9IOjCQXsZyaF3Cy+lys5JzAyf0juYRwJlNEZBX78zJMnX0gz7Ggm436PMOJV8JVAOuaf hojg== X-Received: by 10.180.84.66 with SMTP id w2mr32320349wiy.27.1410874382869; Tue, 16 Sep 2014 06:33:02 -0700 (PDT) Received: from arch-laptop.localdomain (cpc6-nott17-2-0-cust458.12-2.cable.virginm.net. [86.0.53.203]) by mx.google.com with ESMTPSA id fh5sm1919899wib.5.2014.09.16.06.33.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Sep 2014 06:33:02 -0700 (PDT) From: Emil Velikov To: dri-devel@lists.freedesktop.org Subject: [PATCHv2 12/18] Add private mmap/munmap wrappers Date: Tue, 16 Sep 2014 14:31:47 +0100 Message-Id: <1410874307-31520-1-git-send-email-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1410125413-19465-13-git-send-email-emil.l.velikov@gmail.com> References: <1410125413-19465-13-git-send-email-emil.l.velikov@gmail.com> Cc: emil.l.velikov@gmail.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Unlike Linux, Android (bionic) has separate functions - mmap & mmap64. Add a local wrapper (inspired by gallium) that will be used throughout libdrm to combat this bionic feature. v2: - Drop the undefined unlikely macro. - Use macro for munmap under Android. - Wrap long lines. Signed-off-by: Emil Velikov Reviewed-by: Jakob Bornecrantz (v1) --- libdrm.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libdrm.h b/libdrm.h index 23926e6..acfada5 100644 --- a/libdrm.h +++ b/libdrm.h @@ -31,4 +31,59 @@ # define drm_public #endif + +/** + * Static (compile-time) assertion. + * Basically, use COND to dimension an array. If COND is false/zero the + * array size will be -1 and we'll get a compilation error. + */ +#define STATIC_ASSERT(COND) \ + do { \ + (void) sizeof(char [1 - 2*!(COND)]); \ + } while (0) + + +#include + +#if defined(ANDROID) +#include /* for EINVAL */ + +extern void *__mmap2(void *, size_t, int, int, int, size_t); + +static inline void *drm_mmap(void *addr, size_t length, int prot, int flags, + int fd, loff_t offset) +{ + /* offset must be aligned to 4096 (not necessarily the page size) */ + if (offset & 4095) { + errno = EINVAL; + return MAP_FAILED; + } + + return __mmap2(addr, length, prot, flags, fd, (size_t) (offset >> 12)); +} + +# define drm_munmap(addr, length) \ + munmap(addr, length) + + +#else + +/* assume large file support exists */ +# define drm_mmap(addr, length, prot, flags, fd, offset) \ + mmap(addr, length, prot, flags, fd, offset) + + +static inline int drm_munmap(void *addr, size_t length) +{ + /* Copied from configure code generated by AC_SYS_LARGEFILE */ +#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + \ + (((off_t) 1 << 31) << 31)) + STATIC_ASSERT(LARGE_OFF_T % 2147483629 == 721 && + LARGE_OFF_T % 2147483647 == 1); +#undef LARGE_OFF_T + + return munmap(addr, length); +} +#endif + #endif