gfx/skia/trunk/src/utils/android/ashmem.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2008 The Android Open Source Project
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 /*
michael@0 9 * Implementation of the user-space ashmem API for devices, which have our
michael@0 10 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
michael@0 11 * used by the simulator.
michael@0 12 */
michael@0 13
michael@0 14 #include <android/ashmem.h>
michael@0 15
michael@0 16 #include <unistd.h>
michael@0 17 #include <string.h>
michael@0 18 #include <sys/types.h>
michael@0 19 #include <sys/stat.h>
michael@0 20 #include <sys/ioctl.h>
michael@0 21 #include <fcntl.h>
michael@0 22
michael@0 23 #include <linux/ashmem.h>
michael@0 24
michael@0 25 #define ASHMEM_DEVICE "/dev/ashmem"
michael@0 26
michael@0 27 /*
michael@0 28 * ashmem_create_region - creates a new ashmem region and returns the file
michael@0 29 * descriptor, or <0 on error
michael@0 30 *
michael@0 31 * `name' is an optional label to give the region (visible in /proc/pid/maps)
michael@0 32 * `size' is the size of the region, in page-aligned bytes
michael@0 33 */
michael@0 34 int ashmem_create_region(const char *name, size_t size)
michael@0 35 {
michael@0 36 int fd, ret;
michael@0 37
michael@0 38 fd = open(ASHMEM_DEVICE, O_RDWR);
michael@0 39 if (fd < 0)
michael@0 40 return fd;
michael@0 41
michael@0 42 if (name) {
michael@0 43 char buf[ASHMEM_NAME_LEN];
michael@0 44
michael@0 45 strlcpy(buf, name, sizeof(buf));
michael@0 46 ret = ioctl(fd, ASHMEM_SET_NAME, buf);
michael@0 47 if (ret < 0)
michael@0 48 goto error;
michael@0 49 }
michael@0 50
michael@0 51 ret = ioctl(fd, ASHMEM_SET_SIZE, size);
michael@0 52 if (ret < 0)
michael@0 53 goto error;
michael@0 54
michael@0 55 return fd;
michael@0 56
michael@0 57 error:
michael@0 58 close(fd);
michael@0 59 return ret;
michael@0 60 }
michael@0 61
michael@0 62 int ashmem_set_prot_region(int fd, int prot)
michael@0 63 {
michael@0 64 return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
michael@0 65 }
michael@0 66
michael@0 67 int ashmem_pin_region(int fd, size_t offset, size_t len)
michael@0 68 {
michael@0 69 struct ashmem_pin pin = { offset, len };
michael@0 70 return ioctl(fd, ASHMEM_PIN, &pin);
michael@0 71 }
michael@0 72
michael@0 73 int ashmem_unpin_region(int fd, size_t offset, size_t len)
michael@0 74 {
michael@0 75 struct ashmem_pin pin = { offset, len };
michael@0 76 return ioctl(fd, ASHMEM_UNPIN, &pin);
michael@0 77 }
michael@0 78
michael@0 79 int ashmem_get_size_region(int fd)
michael@0 80 {
michael@0 81 return ioctl(fd, ASHMEM_GET_SIZE, NULL);
michael@0 82 }
michael@0 83
michael@0 84 int ashmem_purge_all_caches(int fd)
michael@0 85 {
michael@0 86 return ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL);
michael@0 87 }

mercurial