Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions ashmem.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
// SPDX-License-Identifier: GPL-2.0
/* mm/ashmem.c
*
* Anonymous Shared Memory Subsystem, ashmem
*
* Copyright (C) 2008 Google, Inc.
*
* Robert Love <rlove@google.com>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program 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 General Public License for more details.
*/

#define pr_fmt(fmt) "ashmem: " fmt
Expand Down Expand Up @@ -335,24 +327,23 @@ static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
mutex_lock(&ashmem_mutex);

if (asma->size == 0) {
ret = -EINVAL;
goto out;
mutex_unlock(&ashmem_mutex);
return -EINVAL;
}

if (!asma->file) {
ret = -EBADF;
goto out;
mutex_unlock(&ashmem_mutex);
return -EBADF;
}

mutex_unlock(&ashmem_mutex);

ret = vfs_llseek(asma->file, offset, origin);
if (ret < 0)
goto out;
return ret;

/** Copy f_pos from backing file, since f_ops->llseek() sets it */
file->f_pos = asma->file->f_pos;

out:
mutex_unlock(&ashmem_mutex);
return ret;
}

Expand Down Expand Up @@ -711,30 +702,30 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
size_t pgstart, pgend;
int ret = -EINVAL;

if (unlikely(!asma->file))
return -EINVAL;

if (unlikely(copy_from_user(&pin, p, sizeof(pin))))
return -EFAULT;

mutex_lock(&ashmem_mutex);

if (unlikely(!asma->file))
goto out_unlock;

/* per custom, you can pass zero for len to mean "everything onward" */
if (!pin.len)
pin.len = PAGE_ALIGN(asma->size) - pin.offset;

if (unlikely((pin.offset | pin.len) & ~PAGE_MASK))
return -EINVAL;
goto out_unlock;

if (unlikely(((__u32)-1) - pin.offset < pin.len))
return -EINVAL;
goto out_unlock;

if (unlikely(PAGE_ALIGN(asma->size) < pin.offset + pin.len))
return -EINVAL;
goto out_unlock;

pgstart = pin.offset / PAGE_SIZE;
pgend = pgstart + (pin.len / PAGE_SIZE) - 1;

mutex_lock(&ashmem_mutex);

switch (cmd) {
case ASHMEM_PIN:
ret = ashmem_pin(asma, pgstart, pgend);
Expand All @@ -747,6 +738,7 @@ static int ashmem_pin_unpin(struct ashmem_area *asma, unsigned long cmd,
break;
}

out_unlock:
mutex_unlock(&ashmem_mutex);

return ret;
Expand Down Expand Up @@ -819,7 +811,23 @@ static long compat_ashmem_ioctl(struct file *file, unsigned int cmd,
return ashmem_ioctl(file, cmd, arg);
}
#endif
#ifdef CONFIG_PROC_FS
static void ashmem_show_fdinfo(struct seq_file *m, struct file *file)
{
struct ashmem_area *asma = file->private_data;

mutex_lock(&ashmem_mutex);

if (asma->file)
seq_printf(m, "inode:\t%ld\n", file_inode(asma->file)->i_ino);

if (asma->name[ASHMEM_NAME_PREFIX_LEN] != '\0')
seq_printf(m, "name:\t%s\n",
asma->name + ASHMEM_NAME_PREFIX_LEN);

mutex_unlock(&ashmem_mutex);
}
#endif
static const struct file_operations ashmem_fops = {
.owner = THIS_MODULE,
.open = ashmem_open,
Expand All @@ -831,6 +839,9 @@ static const struct file_operations ashmem_fops = {
#ifdef CONFIG_COMPAT
.compat_ioctl = compat_ashmem_ioctl,
#endif
#ifdef CONFIG_PROC_FS
.show_fdinfo = ashmem_show_fdinfo,
#endif
};

static struct miscdevice ashmem_misc = {
Expand Down Expand Up @@ -865,12 +876,18 @@ static int __init ashmem_init(void)
goto out_free2;
}

register_shrinker(&ashmem_shrinker);
ret = register_shrinker(&ashmem_shrinker);
if (ret) {
pr_err("failed to register shrinker!\n");
goto out_demisc;
}

pr_info("initialized\n");

return 0;

out_demisc:
misc_deregister(&ashmem_misc);
out_free2:
kmem_cache_destroy(ashmem_range_cachep);
out_free1:
Expand Down
1 change: 1 addition & 0 deletions ashmem.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: (GPL-2.0 OR Apache-2.0)
/*
* include/linux/ashmem.h
*
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ashmem-linux (4.16+20180410-1) UNRELEASED; urgency=low

* Sync with v4.16.

-- You-Sheng Yang <vicamo@gmail.com> Tue, 10 Apr 2018 14:54:15 +0800

ashmem-linux (4.15+20180410-1) UNRELEASED; urgency=low

* Sync with v4.15.
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Package: ashmem-dkms
Architecture: all
Depends:
${misc:Depends},
linux-kbuild-4.15,
linux-kbuild-4.16,
Suggests: ashmem-dev
Provides: ashmem-modules
Description: DKMS files to build and install ANDROID ashmem
Expand Down
1 change: 1 addition & 0 deletions uapi/ashmem.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: (GPL-2.0 OR Apache-2.0)
/*
* drivers/staging/android/uapi/ashmem.h
*
Expand Down