From patchwork Sat Nov 3 21:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 992683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-96947-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="W4BtFCrb"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42nXf96Wv5zB4hV for ; Sun, 4 Nov 2018 08:49:37 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=Ak7 H90JW3HKV7CkFWcVInH+LG4eLdCIm8wZeS7L/H/+WaW01AQYGJQZiaE2vfgNkHLE sukdHeYbo72QnRWwY0qMrK1k4suN2bWz3WkKvMMxvApEnjbWJqr95BLXAlZQ1YTj UEPUScCd1b/tqpjmr+tNx9VoF0OGHQepswoPPdIo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=VhusnhNDy wmn39C3LQRFfOmrinA=; b=W4BtFCrbhtX7KCK56JWgzIdol4bbx4yWFB5npmwni XaDhERlJFDtBckbaBn04SkMRBzEPzS/ikp7m73tMmU4EIEGLL2+I2THlCDjPlCsT Xb8ME1Uc/h+p3XEFiIdhdAu86vwaTtBvmnkrUWy7AuM4NZtSgg2W62g38mOryzLp rQ= Received: (qmail 31921 invoked by alias); 3 Nov 2018 21:49:32 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 31910 invoked by uid 89); 3 Nov 2018 21:49:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=cur, HContent-Transfer-Encoding:8bit X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault , commit-hurd@gnu.org Subject: [hurd,commited] hurd: Support msync Date: Sat, 3 Nov 2018 22:49:24 +0100 Message-Id: <20181103214924.13598-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 * sysdeps/mach/hurd/msync.c: New file. --- ChangeLog | 4 ++ sysdeps/mach/hurd/msync.c | 93 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 sysdeps/mach/hurd/msync.c diff --git a/ChangeLog b/ChangeLog index 497f5b721c..ef268e8337 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2018-11-03 Samuel Thibault + + * sysdeps/mach/hurd/msync.c: New file. + 2018-11-02 Florian Weimer * support/shell-container.c (copy_func): Call diff --git a/sysdeps/mach/hurd/msync.c b/sysdeps/mach/hurd/msync.c new file mode 100644 index 0000000000..3e41503ece --- /dev/null +++ b/sysdeps/mach/hurd/msync.c @@ -0,0 +1,93 @@ +/* msync -- Synchronize mapped memory to external storage. Mach version. + Copyright (C) 2002-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +#include + +/* Synchronize the region starting at ADDR and extending LEN bytes with the + file it maps. Filesystem operations on a file being mapped are + unpredictable before this is done. */ + +int +msync (void *addr, size_t length, int flags) +{ + boolean_t should_flush = flags & MS_INVALIDATE ? 1 : 0; + boolean_t should_iosync = flags & MS_ASYNC ? 0 : 1; + + vm_address_t cur = (vm_address_t) addr; + vm_address_t target = cur + length; + + vm_size_t len; + vm_prot_t prot; + vm_prot_t max_prot; + vm_inherit_t inherit; + boolean_t shared; + memory_object_name_t obj; + vm_offset_t offset; + + kern_return_t err; + + if (flags & (MS_SYNC | MS_ASYNC) == (MS_SYNC | MS_ASYNC)) + return __hurd_fail (EINVAL); + + while (cur < target) + { + vm_address_t begin = cur; + + err = __vm_region (__mach_task_self (), + &begin, &len, &prot, &max_prot, &inherit, + &shared, &obj, &offset) + + if (err != KERN_SUCCESS) + return __hurd_fail (err); + + if (begin > cur) + /* We were given an address before the first region, + or we found a hole. */ + cur = begin; + + if (cur >= target) + /* We were given an ending address within a hole. */ + break; + + if (MACH_PORT_VALID (obj)) + { + vm_size_t sync_len; + + if (begin + len > target) + sync_len = target - begin; + else + sync_len = len; + + err = __vm_object_sync (obj, cur - begin + offset, sync_len, + should_flush, 1, should_iosync); + __mach_port_deallocate (__mach_task_self (), obj); + + if (err) + return __hurd_fail (err); + + } + + cur = begin + len; + } + + return 0; +}