Commit 46480a97 authored by John Levon's avatar John Levon Committed by Linus Torvalds

[PATCH] OProfile: export kernel pointer size in oprofilefs

Tell user-space how big kernel pointers are, as preferable to sniffing /proc/kcore.
Improve the oprofilefs_ulong_to_user() prototype.
parent a5a107f0
...@@ -19,6 +19,17 @@ unsigned long fs_cpu_buffer_size = 8192; ...@@ -19,6 +19,17 @@ unsigned long fs_cpu_buffer_size = 8192;
unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */ unsigned long fs_buffer_watershed = 32768; /* FIXME: tune */
static ssize_t pointer_size_read(struct file * file, char * buf, size_t count, loff_t * offset)
{
return oprofilefs_ulong_to_user((unsigned long)sizeof(void *), buf, count, offset);
}
static struct file_operations pointer_size_fops = {
.read = pointer_size_read,
};
static ssize_t cpu_type_read(struct file * file, char * buf, size_t count, loff_t * offset) static ssize_t cpu_type_read(struct file * file, char * buf, size_t count, loff_t * offset)
{ {
return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset); return oprofilefs_str_to_user(oprofile_ops->cpu_type, buf, count, offset);
...@@ -32,7 +43,7 @@ static struct file_operations cpu_type_fops = { ...@@ -32,7 +43,7 @@ static struct file_operations cpu_type_fops = {
static ssize_t enable_read(struct file * file, char * buf, size_t count, loff_t * offset) static ssize_t enable_read(struct file * file, char * buf, size_t count, loff_t * offset)
{ {
return oprofilefs_ulong_to_user(&oprofile_started, buf, count, offset); return oprofilefs_ulong_to_user(oprofile_started, buf, count, offset);
} }
...@@ -85,6 +96,7 @@ void oprofile_create_files(struct super_block * sb, struct dentry * root) ...@@ -85,6 +96,7 @@ void oprofile_create_files(struct super_block * sb, struct dentry * root)
oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed); oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed);
oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size); oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size);
oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
oprofile_create_stats_files(sb, root); oprofile_create_stats_files(sb, root);
if (oprofile_ops->create_files) if (oprofile_ops->create_files)
oprofile_ops->create_files(sb, root); oprofile_ops->create_files(sb, root);
......
...@@ -69,7 +69,7 @@ ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_ ...@@ -69,7 +69,7 @@ ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_
#define TMPBUFSIZE 50 #define TMPBUFSIZE 50
ssize_t oprofilefs_ulong_to_user(unsigned long * val, char * buf, size_t count, loff_t * offset) ssize_t oprofilefs_ulong_to_user(unsigned long val, char * buf, size_t count, loff_t * offset)
{ {
char tmpbuf[TMPBUFSIZE]; char tmpbuf[TMPBUFSIZE];
size_t maxlen; size_t maxlen;
...@@ -78,7 +78,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long * val, char * buf, size_t count, ...@@ -78,7 +78,7 @@ ssize_t oprofilefs_ulong_to_user(unsigned long * val, char * buf, size_t count,
return 0; return 0;
spin_lock(&oprofilefs_lock); spin_lock(&oprofilefs_lock);
maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", *val); maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
spin_unlock(&oprofilefs_lock); spin_unlock(&oprofilefs_lock);
if (maxlen > TMPBUFSIZE) if (maxlen > TMPBUFSIZE)
maxlen = TMPBUFSIZE; maxlen = TMPBUFSIZE;
...@@ -122,7 +122,8 @@ int oprofilefs_ulong_from_user(unsigned long * val, char const * buf, size_t cou ...@@ -122,7 +122,8 @@ int oprofilefs_ulong_from_user(unsigned long * val, char const * buf, size_t cou
static ssize_t ulong_read_file(struct file * file, char * buf, size_t count, loff_t * offset) static ssize_t ulong_read_file(struct file * file, char * buf, size_t count, loff_t * offset)
{ {
return oprofilefs_ulong_to_user(file->private_data, buf, count, offset); unsigned long * val = file->private_data;
return oprofilefs_ulong_to_user(*val, buf, count, offset);
} }
...@@ -212,9 +213,8 @@ int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root, ...@@ -212,9 +213,8 @@ int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
static ssize_t atomic_read_file(struct file * file, char * buf, size_t count, loff_t * offset) static ssize_t atomic_read_file(struct file * file, char * buf, size_t count, loff_t * offset)
{ {
atomic_t * aval = file->private_data; atomic_t * val = file->private_data;
unsigned long val = atomic_read(aval); return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
return oprofilefs_ulong_to_user(&val, buf, count, offset);
} }
......
...@@ -92,7 +92,7 @@ ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_ ...@@ -92,7 +92,7 @@ ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_
* Convert an unsigned long value into ASCII and copy it to the user buffer @buf, * Convert an unsigned long value into ASCII and copy it to the user buffer @buf,
* updating *offset appropriately. Returns bytes written or -EFAULT. * updating *offset appropriately. Returns bytes written or -EFAULT.
*/ */
ssize_t oprofilefs_ulong_to_user(unsigned long * val, char * buf, size_t count, loff_t * offset); ssize_t oprofilefs_ulong_to_user(unsigned long val, char * buf, size_t count, loff_t * offset);
/** /**
* Read an ASCII string for a number from a userspace buffer and fill *val on success. * Read an ASCII string for a number from a userspace buffer and fill *val on success.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment