Exemplo n.º 1
0
static void child_loop_alloc(unsigned long long alloc_bytes)
{
	unsigned long bytecount = 0;
	char *mem;

	tst_res(TINFO, "... child %d starting", getpid());

	while (1) {
		mem = SAFE_MALLOC(chunksize);
		if (dowrite)
			do_write_mem(mem, chunksize);

		if (verbose)
			tst_res(TINFO,
				"child %d allocated %lu bytes chunksize is %d",
				getpid(), bytecount, chunksize);
		bytecount += chunksize;
		if (bytecount >= alloc_bytes)
			break;
	}
	if (dowrite)
		tst_res(TINFO, "... [t=%d] %lu bytes allocated and used in child %d",
				tst_timeout_remaining(), bytecount, getpid());
	else
		tst_res(TINFO, "... [t=%d] %lu bytes allocated only in child %d",
				tst_timeout_remaining(), bytecount, getpid());

	kill(getppid(), SIGRTMIN);
	raise(SIGSTOP);
	exit(0);
}
Exemplo n.º 2
0
static ssize_t write_mem(struct file * file, const char __user * buf, 
			 size_t count, loff_t *ppos)
{
	unsigned long p = *ppos;

	if (!valid_phys_addr_range(p, &count))
		return -EFAULT;
	return do_write_mem(__va(p), p, buf, count, ppos);
}
Exemplo n.º 3
0
/*
 * This function writes to the *virtual* memory as seen by the kernel.
 */
static ssize_t write_kmem(struct file * file, const char __user * buf, 
			  size_t count, loff_t *ppos)
{
	unsigned long p = *ppos;
	ssize_t wrote = 0;
	ssize_t virtr = 0;
	ssize_t written;
	char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */

	if (p < (unsigned long) high_memory) {

		wrote = count;
		if (count > (unsigned long) high_memory - p)
			wrote = (unsigned long) high_memory - p;

		written = do_write_mem((void*)p, p, buf, wrote, ppos);
		if (written != wrote)
			return written;
		wrote = written;
		p += wrote;
		buf += wrote;
		count -= wrote;
	}

	if (count > 0) {
		kbuf = (char *)__get_free_page(GFP_KERNEL);
		if (!kbuf)
			return wrote ? wrote : -ENOMEM;
		while (count > 0) {
			int len = count;

			if (len > PAGE_SIZE)
				len = PAGE_SIZE;
			if (len) {
				written = copy_from_user(kbuf, buf, len);
				if (written) {
					ssize_t ret;

					free_page((unsigned long)kbuf);
					ret = wrote + virtr + (len - written);
					return ret ? ret : -EFAULT;
				}
			}
			len = vwrite(kbuf, (char *)p, len);
			count -= len;
			buf += len;
			virtr += len;
			p += len;
		}
		free_page((unsigned long)kbuf);
	}

 	*ppos = p;
 	return virtr + wrote;
}
Exemplo n.º 4
0
Arquivo: mem.c Projeto: davidbau/davej
/*
 * This function writes to the *virtual* memory as seen by the kernel.
 */
static ssize_t write_kmem(struct file * file, const char * buf, 
			  size_t count, loff_t *ppos)
{
	unsigned long p = *ppos;

	if (p >= (unsigned long) high_memory)
		return 0;
	if (count > (unsigned long) high_memory - p)
		count = (unsigned long) high_memory - p;
	return do_write_mem(file, (void*)p, p, buf, count, ppos);
}
Exemplo n.º 5
0
static ssize_t write_mem(struct file * file, const char * buf, 
			 size_t count, loff_t *ppos)
{
	unsigned long p = *ppos;
	unsigned long end_mem;

	end_mem = __pa(high_memory);
	if (p >= end_mem)
		return 0;
	if (count > end_mem - p)
		count = end_mem - p;
	return do_write_mem(file, __va(p), p, buf, count, ppos);
}