~ci-train-bot/mir/mir-ubuntu-zesty-2683

« back to all changes in this revision

Viewing changes to 3rd_party/android-input/android/frameworks/native/libs/utils/FileMap.cpp

  • Committer: Bileto Bot
  • Date: 2017-04-13 15:26:17 UTC
  • mfrom: (1160.2883.164 0.27)
  • Revision ID: ci-train-bot@canonical.com-20170413152617-bs7slz07xbzxu2d3
* New upstream release 0.27.0 (https://launchpad.net/mir/+milestone/0.27.0)
  - ABI summary:
    . mirclient ABI unchanged at 9
    . mirserver ABI bumped to 44
    . mircommon ABI unchanged at 7
    . mirplatform ABI bumped to 61
    . mirprotobuf ABI unchanged at 3
    . mirplatformgraphics ABI bumped to 13
    . mirclientplatform ABI unchanged at 5
    . mirinputplatform ABI bumped to 7
    . mircore ABI unchanged at 1
  - Enhancements:
    . Mostly groundwork required to support major enhancements coming in
      future Mir versions.
    . Removed android-input and eliminated the entire "3rd_party/" subtree.
      Now the Mir source tree contains original code only.
    . Added mir_prompt_session_new_fds_for_prompt_providers_sync API.
    . mirout: Added load and save options for keeping display configs
      on disk.
    . mirout: Added "--" support for applying configuration changes under
      Unity8.
    . Fixed failure of DRM hardware cursor {hide(); show(image);}
    . Added server option: "--cursor software" (MIR_SERVER_CURSOR=software)
    . Added letterboxing/black bars support to the GL renderer in preparation
      for generic output cloning.
    . Added client API for getting the logical size of an output.
    . Migrated MirCookie to use SHA-256.
    . Ensure RealKMSOutputConfiguration stays in sync with actual hardware
      state.
    . Added support for drag-and-drop.
    . Lots of other client API enhancements.
    . Minor clean-ups, optimizations and dead code removal.
  - Bugs fixed:
    . [enhancement] Make able to get version information from client /
      server APIs (LP: #1195540)
    . Touch screen coordinates don't rotate with the screen (LP: #1349660)
    . Subpixel order not included in Mir display information (LP: #1393578)
    . [enhancement] Missing client API for relative surface movement (e.g.
      dragging client-decorated windows) (LP: #1420334) . Mir does not reset
      key states when paused or resumed (modifiers get stuck after VT
      switching) (LP: #1536279)
    . Inconsistent behaviour of Num Lock (LP: #1588237)
    . [ FAILED ] NestedInput.nested_event_filter_receives_keyboard_from_host
      (LP: #1613523)
    . Rotating an output left or right without restarting the
      compositor distorts the image (LP: #1643488)
    . support display scaling slider in unity8 (LP: #1645372)
    . [ FAILED ] NestedInputWithMouse.mouse_pointer_coordinates_in_nested_
      server_are_accumulated (LP: #1646375)
    . [ FAILED ] NestedInputWithMouse.mouse_pointer_position_is_in_sync_with_
      host_server (LP: #1646558)
    . abi_check doesn't check mircore (LP: #1649354)
    . Under Unity8, mir_demo_client_target is distorted and input in the
      wrong place on start-up (LP: #1655804)
    . [testsfail] PromptSessionClientAPI.client_pid_is_associated_with_
      session hangs and times out (LP: #1655929)
    . EDID does not change when hotplugging a monitor (LP: #1660017)
    . [regression] Mir 0.26.0 - spinner loading animation, minimize, maximize
      too fast (LP: #1661072)
    . [regression] Unity8 stutters constantly (like half frame rate) using
      Mir 0.26.0 (LP: #1661128)
    . [regression] mir_demo_server refuses to quit on Ctrl+Alt+Backspace or
      Ctrl+C in its terminal (deadlock in DefaultInputDeviceHub::add_device)
      (LP: #1661151)
    . [regression] mirout crashes when connecting to unity8 or any nested
      server: [libprotobuf FATAL
      /usr/include/google/protobuf/repeated_field.h:1408] CHECK failed:
      (index) < (current_size_): (LP: #1661163)
    . [ FAILED ] DefaultInputManagerTest.forwards_pause_continue_state_
      changes_to_platform (LP: #1661187)
    . [regression] Segfault on detect_fd_leaks during acceptance tests (in
      DisplayConfiguration/{DisplayFormatSetting,DisplaySubpixelSetting})
      (LP: #1661498)
    . [regression] Nested server segfaults or rapidly logs exceptions when a
      fullscreen client starts [in mir_presentation_chain_set_dropping_mode
      ... std::exception::what: Operation not permitted] (LP: #1661508)
    . [regression] Windowed clients of nested servers are all black
      (LP: #1661521)
    . mir_window_request_persistent_id_sync seg faults when called twice
      (LP: #1661704)
    . mir_acceptance_tests now takes 10 seconds longer (in r4002 compared to
      r4001) (LP: #1662044)
    . Mir graphics platform ABI broke in series 0.26 but sonames never
      changed (LP: #1662455)
    . libmirclient-dev missing build depndency on libmircore-dev
      (LP: #1662942)
    . [regression] mirscreencast hangs during screencast creation
      (LP: #1662997)
    . [regression] Software clients of nested servers with size >=480x480
      are all black in Mir 0.25.0 and later (or stretched and distorted under
      Unity8) (LP: #1663062)
    . mir_window_spec_set_cursor_name() doesn't trigger
      mir::scene::SurfaceObserver::cursor_image_set_to (LP: #1663197)
    . android complaint during mirscreencast of nested server (LP: #1664562)
    . qtubuntu sends wrong text as part of QKeyEvent (LP: #1664610)
    . Mir server crashed with SIGSEGV in
      mir::compositor::TemporaryBuffer::size() called from
      mir::gl::tessellate_renderable_into_rectangle() (LP: #1664760)
    . mirout reports logical size of a rotated display incorrectly
      (LP: #1665271)
    . Nested servers (Unity8) periodically stutter (half frame rate) with
      Mir 0.26.1 (LP: #1666372)
    . If the only surface in a session cannot take focus the server crashes
      (LP: #1667645)
    . [regression] OSK input shaping no longer works correctly (LP: #1669444)
    . GTK window functions `Always on Top, Move and Resize' don't work in
      Mir/Unity8 (LP: #1669524)
    . [regression] mir_proving_server mode hotkeys (Ctrl+Alt+=/-) cause the
      server to segfault (LP: #1669752)
    . Test takes minutes to complete: MediatingDisplayChangerTest.confirmed_
      configuration_doesnt_revert_after_timeout (LP: #1671033)
    . [ FAILED ] PosixRWMutex.prefer_writer_nonrecursive_prevents_writer_
      starvation (Timeout waiting to acquire write lock) (LP: #1671037)
    . [regression] Mixing screen rotation with mode changes makes the image
      squished (LP: #1672269)
    . unity-system-compositor crashed with SIGSEGV in
      libinput_device_config_accel_is_available() from
      libinput_device_config_accel_set_speed() from
      mir::input::evdev::LibInputDevice::apply_settings() (LP: #1672955)
    . Presentation chains should support various Vulkan presentation modes
      (LP: #1673533)
    . Need an extension for GBM buffers to replace
      mir_buffer_get_buffer_package() (LP: #1673534)
    . cross-compile-chroot.sh (to zesty) fails to build [cannot find -ludev]
      due to libudev.so being in a different directory to where libudev.pc
      searches for it (LP: #1674201)
    . Please transition to Boost 1.62 (LP: #1675138)
    . [regression] Mir is assigning the first output ID = 0 (==
      mir_display_output_id_invalid) (LP: #1675331)
    . Mir sending key repeat events continually to nested shell after VT
      switch (causes Unity8 lockup for a while) (LP: #1675357)
    . mirout commands don't work when followed by -- (LP: #1676320)
    . mir_demo_standalone_render_overlays fails to link (LP: #1677239)
    . [regression] doxygen processing for capnproto/protobuf broken
      (LP: #1679248)
    . mir_window_spec_set_cursor_render_surface does not work (LP: #1679836)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2006 The Android Open Source Project
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
//
18
 
// Shared file mapping class.
19
 
//
20
 
 
21
 
#define LOG_TAG "filemap"
22
 
 
23
 
#include <utils/FileMap.h>
24
 
#include <std/Log.h>
25
 
 
26
 
#include <stdio.h>
27
 
#include <stdlib.h>
28
 
 
29
 
#ifdef HAVE_POSIX_FILEMAP
30
 
#include <sys/mman.h>
31
 
#endif
32
 
 
33
 
#include <string.h>
34
 
#include <memory.h>
35
 
#include <errno.h>
36
 
#include <assert.h>
37
 
 
38
 
using namespace android;
39
 
 
40
 
/*static*/ long FileMap::mPageSize = -1;
41
 
 
42
 
 
43
 
/*
44
 
 * Constructor.  Create an empty object.
45
 
 */
46
 
FileMap::FileMap(void)
47
 
    : mRefCount(1), mFileName(NULL), mBasePtr(NULL), mBaseLength(0),
48
 
      mDataPtr(NULL), mDataLength(0)
49
 
{
50
 
}
51
 
 
52
 
/*
53
 
 * Destructor.
54
 
 */
55
 
FileMap::~FileMap(void)
56
 
{
57
 
    assert(mRefCount == 0);
58
 
 
59
 
    //printf("+++ removing FileMap %p %u\n", mDataPtr, mDataLength);
60
 
 
61
 
    mRefCount = -100;       // help catch double-free
62
 
    if (mFileName != NULL) {
63
 
        free(mFileName);
64
 
    }
65
 
#ifdef HAVE_POSIX_FILEMAP    
66
 
    if (mBasePtr && munmap(mBasePtr, mBaseLength) != 0) {
67
 
        ALOGD("munmap(%p, %d) failed\n", mBasePtr, (int) mBaseLength);
68
 
    }
69
 
#endif
70
 
#ifdef HAVE_WIN32_FILEMAP
71
 
    if (mBasePtr && UnmapViewOfFile(mBasePtr) == 0) {
72
 
        ALOGD("UnmapViewOfFile(%p) failed, error = %ld\n", mBasePtr,
73
 
              GetLastError() );
74
 
    }
75
 
    if (mFileMapping != INVALID_HANDLE_VALUE) {
76
 
        CloseHandle(mFileMapping);
77
 
    }
78
 
    CloseHandle(mFileHandle);
79
 
#endif
80
 
}
81
 
 
82
 
 
83
 
/*
84
 
 * Create a new mapping on an open file.
85
 
 *
86
 
 * Closing the file descriptor does not unmap the pages, so we don't
87
 
 * claim ownership of the fd.
88
 
 *
89
 
 * Returns "false" on failure.
90
 
 */
91
 
bool FileMap::create(const char* origFileName, int fd, off64_t offset, size_t length,
92
 
        bool readOnly)
93
 
{
94
 
#ifdef HAVE_WIN32_FILEMAP
95
 
    int     adjust;
96
 
    off64_t adjOffset;
97
 
    size_t  adjLength;
98
 
 
99
 
    if (mPageSize == -1) {
100
 
        SYSTEM_INFO  si;
101
 
        
102
 
        GetSystemInfo( &si );
103
 
        mPageSize = si.dwAllocationGranularity;
104
 
    }
105
 
 
106
 
    DWORD  protect = readOnly ? PAGE_READONLY : PAGE_READWRITE;
107
 
    
108
 
    mFileHandle  = (HANDLE) _get_osfhandle(fd);
109
 
    mFileMapping = CreateFileMapping( mFileHandle, NULL, protect, 0, 0, NULL);
110
 
    if (mFileMapping == NULL) {
111
 
        ALOGE("CreateFileMapping(%p, %lx) failed with error %ld\n",
112
 
              mFileHandle, protect, GetLastError() );
113
 
        return false;
114
 
    }
115
 
    
116
 
    adjust    = offset % mPageSize;
117
 
    adjOffset = offset - adjust;
118
 
    adjLength = length + adjust;
119
 
    
120
 
    mBasePtr = MapViewOfFile( mFileMapping, 
121
 
                              readOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS,
122
 
                              0,
123
 
                              (DWORD)(adjOffset),
124
 
                              adjLength );
125
 
    if (mBasePtr == NULL) {
126
 
        ALOGE("MapViewOfFile(%ld, %ld) failed with error %ld\n",
127
 
              adjOffset, adjLength, GetLastError() );
128
 
        CloseHandle(mFileMapping);
129
 
        mFileMapping = INVALID_HANDLE_VALUE;
130
 
        return false;
131
 
    }
132
 
#endif
133
 
#ifdef HAVE_POSIX_FILEMAP
134
 
    int     prot, flags, adjust;
135
 
    off64_t adjOffset;
136
 
    size_t  adjLength;
137
 
 
138
 
    void* ptr;
139
 
 
140
 
    assert(mRefCount == 1);
141
 
    assert(fd >= 0);
142
 
    assert(offset >= 0);
143
 
    assert(length > 0);
144
 
 
145
 
    /* init on first use */
146
 
    if (mPageSize == -1) {
147
 
#if NOT_USING_KLIBC
148
 
        mPageSize = sysconf(_SC_PAGESIZE);
149
 
        if (mPageSize == -1) {
150
 
            ALOGE("could not get _SC_PAGESIZE\n");
151
 
            return false;
152
 
        }
153
 
#else
154
 
        /* this holds for Linux, Darwin, Cygwin, and doesn't pain the ARM */
155
 
        mPageSize = 4096;
156
 
#endif
157
 
    }
158
 
 
159
 
    adjust   = offset % mPageSize;
160
 
try_again:
161
 
    adjOffset = offset - adjust;
162
 
    adjLength = length + adjust;
163
 
 
164
 
    flags = MAP_SHARED;
165
 
    prot = PROT_READ;
166
 
    if (!readOnly)
167
 
        prot |= PROT_WRITE;
168
 
 
169
 
    ptr = mmap(NULL, adjLength, prot, flags, fd, adjOffset);
170
 
    if (ptr == MAP_FAILED) {
171
 
        // Cygwin does not seem to like file mapping files from an offset.
172
 
        // So if we fail, try again with offset zero
173
 
        if (adjOffset > 0) {
174
 
                adjust = offset;
175
 
                goto try_again;
176
 
        }
177
 
    
178
 
        ALOGE("mmap(%ld,%ld) failed: %s\n",
179
 
            (long) adjOffset, (long) adjLength, strerror(errno));
180
 
        return false;
181
 
    }
182
 
    mBasePtr = ptr;
183
 
#endif /* HAVE_POSIX_FILEMAP */
184
 
 
185
 
    mFileName = origFileName != NULL ? strdup(origFileName) : NULL;
186
 
    mBaseLength = adjLength;
187
 
    mDataOffset = offset;
188
 
    mDataPtr = (char*) mBasePtr + adjust;
189
 
    mDataLength = length;
190
 
 
191
 
    assert(mBasePtr != NULL);
192
 
 
193
 
    ALOGV("MAP: base %p/%d data %p/%d\n",
194
 
        mBasePtr, (int) mBaseLength, mDataPtr, (int) mDataLength);
195
 
 
196
 
    return true;
197
 
}
198
 
 
199
 
/*
200
 
 * Provide guidance to the system.
201
 
 */
202
 
int FileMap::advise(MapAdvice advice)
203
 
{
204
 
#if HAVE_MADVISE
205
 
    int cc, sysAdvice;
206
 
 
207
 
    switch (advice) {
208
 
        case NORMAL:        sysAdvice = MADV_NORMAL;        break;
209
 
        case RANDOM:        sysAdvice = MADV_RANDOM;        break;
210
 
        case SEQUENTIAL:    sysAdvice = MADV_SEQUENTIAL;    break;
211
 
        case WILLNEED:      sysAdvice = MADV_WILLNEED;      break;
212
 
        case DONTNEED:      sysAdvice = MADV_DONTNEED;      break;
213
 
        default:
214
 
                            assert(false);
215
 
                            return -1;
216
 
    }
217
 
 
218
 
    cc = madvise(mBasePtr, mBaseLength, sysAdvice);
219
 
    if (cc != 0)
220
 
        ALOGW("madvise(%d) failed: %s\n", sysAdvice, strerror(errno));
221
 
    return cc;
222
 
#else
223
 
        return -1;
224
 
#endif // HAVE_MADVISE
225
 
}