What makes Zalloc (ZFS) not stable on 32-bit system?
Why it works on 64bit system.
Why it works on 64bit system.
EXPERT IN MIPI-DSI/DPI/DCS LCD/TSP SINGLE OR DUAL PANEL BRING UP @ ALL LEVELS OF ANDROID STACK. Working for EMBEDDED SOFTWARE LABS. This site is owned by M.PHANI RAJ KIRAN M.Tech INDIA.(c):watisid@rediffmail URL: www.embeddedsoftwarelabs.com http://in.linkedin.com/pub/phanirajkiran-mallapuram/63/916/884
#define IH_OS_LINUX 5 /* Linux */
#define IH_CPU_ARM 2 /* ARM */
LA LA LA HA HA HA HA : Magic number :
#define IH_MAGIC 0x27051956 /* Image Magic Number */
Lol looks like a birthday date : 27th May 1956.
Abooo U-boot header :
typedef struct uboot_image_header {
uint32_t ih_magic; /* Image Header Magic Number */
uint32_t ih_hcrc; /* Image Header CRC Checksum */
uint32_t ih_time; /* Image Creation Timestamp */
uint32_t ih_size; /* Image Data Size */
uint32_t ih_load; /* Data Load Address */
uint32_t ih_ep; /* Entry Point Address */
uint32_t ih_dcrc; /* Image Data CRC Checksum */
uint8_t ih_os; /* Operating System */
uint8_t ih_arch; /* CPU architecture */
uint8_t ih_type; /* Image Type */
uint8_t ih_comp; /* Compression Type */
uint8_t ih_name[IH_NMLEN]; /* Image Name */
} uboot_image_header_t;
int register_chrdev(unsigned int major, const char *name,
const struct file_operations *fops);
int unregister_chrdev(unsigned int major, const char *name);
In the old days, register_chrdev() would allocate all 256 minor numbers associated with the given major, associating the given name and file operations with all of them. If the major number is given as zero, one will be allocated on the fly. The corresponding unregister_chrdev() call would release all of those minor numbers. This call asked for the name as a safety measure; if the name did not match that provided when the major number was registered, the unregister_chrdev() call would fail. int register_chrdev_region(dev_t first, unsigned int count,
const char *name);
int alloc_chrdev_region(dev_t *first, unsigned int firstminor,
unsigned int count, char *name);
The first form will allocate count minor numbers, starting with the major/minor pair found in first, and remembering name with all of them. The second form is intended for use when the desired major number is not known ahead of time; it will allocate a major number, then allocate countminor numbers, starting at firstminor. The beginning of the allocated number range will be returned in first. The return value will be zero on success or a negative error code on failure.void unregister_chrdev_region(dev_t first, unsigned int count);The association of device numbers with specific devices happens by way of the cdev structure, found in
struct cdev *my_dev = cdev_alloc();
if (my_dev != NULL)
my_dev->ops = &my_fops; /* The file_operations structure */
my_dev->owner = THIS_MODULE;
else
/* No memory, we lose */
In the more common usage pattern, however, the cdev structure will be embedded within some larger, device-specific structure, and it will be allocated with that structure. In this case, the function to initialize the cdev is: void cdev_init(struct cdev *cdev, const struct file_operations *fops);
/* Need to set ->owner separately */
Either way, the structure is put into proper operating condition, and it will be equipped with the file_operations which should be invoked for the associated device. The owner field of the structure should be initialized to THIS_MODULE to protect against ill-advised module unloads while the device is active.int cdev_add(struct cdev *cdev, dev_t first, unsigned int count);This function will add cdev to the system. It will service operations for the count device numbers starting with first; a cdev will often serve a single device number, but it does not have to be that way. Note that cdev_add() can fail; if the return code is zero, the device has not been added to the system.
void cdev_del(struct cdev *cdev);The cdev should not be referenced after this call. In particular, if cdev was obtained with cdev_alloc(), it will likely be freed in cdev_del().
This set of patches implements the core Linux support for the AArch64 (64-bit ARM) architecture. ARM introduced AArch64 as part of the ARMv8 architecture and consists of a substantially revised exception model (with 4 exception levels: EL0 - user, EL1 - kernel, EL2 - hypervisor, EL3 - secure monitor), new A64 instruction set based on larger register file, new FP/SIMD instructions. The new ABI is LP64 and takes advantage of the larger register file and mandates FP. AArch64 documentation currently available (publicly, though click-through agreement required): - Instruction Set Overview: http://infocenter.arm.com/help/topic/com.arm.doc.genc0101... - ABI (PCS, ELF, DWARF, C++): http://infocenter.arm.com/help/topic/com.arm.doc.ihi0059a...
These patches are also available on this branch: git://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/linux-aarch64.git upstream
#includevoid f(void) { int* x = malloc(10 * sizeof(int)); x[10] = 0; // problem 1: heap block overrun } // problem 2: memory leak -- x not freed int main(void) { f(); return 0; }
You can compile and run it as follows to detect problems:
gcc test.c
valgrind --log-file=output.file --leak-check=yes --tool=memcheck ./a.out
vi output.file
How Do I use Valgrind?
If you normally run your program like this:
./a.out arg1 arg2
OR
/path/to/myapp arg1 arg2
Use this command line to turn on the detailed memory leak detector:
valgrind --leak-check=yes ./a.out arg1 arg2
valgrind --leak-check=yes /path/to/myapp arg1 arg2
You can also set logfile:
valgrind --log-file=output.file --leak-check=yes --tool=memcheck ./a.out arg1 arg2
Most error messages look like the following:
cat output.file
Detecting kernel memory leaks
http://lwn.net/Articles/187979/
asmlinkage void __init start_kernel(void)
{
char * command_line;
extern const struct kernel_param __start___param[], __stop___param[];
// ATAG,DTB 정보로 사용
...
proc_caches_init();
// sighand_struct, signal_struct, files_struct, fs_struct, mm_struct, vm_area_struct, nsproxy
// 를 사용하기 위한 kmem_cache 할당자 및 percpu list 초기화 수행
buffer_init();
// buffer_head 를 사용하기 위한 kmem_cache 할당자 및 max_buffer_heads 값 초기화 수행
key_init(); // null funtion
security_init(); // null funtion
dbg_late_init(); // null funtion
// totalram_pages: 총 free된 page 수
vfs_caches_init(totalram_pages);
// ARM10C 20151003
// totalram_pages: 총 free된 page 수
void __init vfs_caches_init(unsigned long mempages)
{
unsigned long reserve;
// mempages: 총 free된 page 수, nr_free_pages(): 현재의 free pages 수
reserve = min((mempages - nr_free_pages()) * 3/2, mempages - 1);
// reserve: XXX
// mempages: 총 free된 page 수, reserve: XXX
mempages -= reserve;
// mempages: 총 free된 page 수 - XXX
// PATH_MAX: 4096
// SLAB_HWCACHE_ALIGN: 0x00002000UL, SLAB_PANIC: 0x00040000UL
// kmem_cache_create("names_cache", 4096, 0, 0x42000, NULL): kmem_cache#6
names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
// names_cachep: kmem_cache#6
dcache_init();
inode_init();
// mempages: 총 free된 page 수 - XXX
files_init(mempages);
mnt_init();
// ARM10C 20151024
void __init mnt_init(void)
{
unsigned u;
int err;
// sizeof(struct mount): 152 bytes, SLAB_HWCACHE_ALIGN: 0x00002000UL, SLAB_PANIC: 0x00040000UL
// kmem_cache_create("mnt_cache", 152, 0, 0x42000, NULL): kmem_cache#2
mnt_cache = kmem_cache_create("mnt_cache", sizeof(struct mount),
0, SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
// mnt_cache: kmem_cache#2
// sizeof(struct hlist_head): 4 bytes, mhash_entries: 0
// alloc_large_system_hash("Mount-cache", 4, 0, 19, 0, &m_hash_shift, &m_hash_mask, 0, 0): 16kB만큼 할당받은 메모리 주소
mount_hashtable = alloc_large_system_hash("Mount-cache",
sizeof(struct hlist_head),
mhash_entries, 19,
0,
&m_hash_shift, &m_hash_mask, 0, 0);
// mount_hashtable: 16kB만큼 할당받은 메모리 주소
// sizeof(struct hlist_head): 4 bytes, mphash_entries: 0
// alloc_large_system_hash("Mountpoint-cache", 4, 0, 19, 0, &m_hash_shift, &m_hash_mask, 0, 0): 16kB만큼 할당받은 메모리 주소
mountpoint_hashtable = alloc_large_system_hash("Mountpoint-cache",
sizeof(struct hlist_head),
mphash_entries, 19,
0,
&mp_hash_shift, &mp_hash_mask, 0, 0);
// mountpoint_hashtable: 16kB만큼 할당받은 메모리 주소
// mount_hashtable: 16kB만큼 할당받은 메모리 주소, mountpoint_hashtable: 16kB만큼 할당받은 메모리 주소
if (!mount_hashtable || !mountpoint_hashtable)
panic("Failed to allocate mount hash table\n");
// m_hash_mask: 0xFFF
for (u = 0; u <= m_hash_mask; u++)
// u: 0
INIT_HLIST_HEAD(&mount_hashtable[u]);
// INIT_HLIST_HEAD 에서 한일:
// ((&mount_hashtable[0])->first = NULL)
// u: 1...4095 까지 loop 수행
// mp_hash_mask: 0xFFF
for (u = 0; u <= mp_hash_mask; u++)
// u: 0
INIT_HLIST_HEAD(&mountpoint_hashtable[u]);
// INIT_HLIST_HEAD 에서 한일:
// ((&mountpoint_hashtable[0])->first = NULL)
// u: 1...4095 까지 loop 수행
// sysfs_init(): 0
err = sysfs_init();
// err: 0
// err: 0
if (err)
printk(KERN_WARNING "%s: sysfs_init error: %d\n",
__func__, err);
fs_kobj = kobject_create_and_add("fs", NULL);
// ARM10C 20160109
// "fs", NULL
struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
{
struct kobject *kobj;
int retval;
// kobject_create(): kmem_cache#30-oX (struct kobject)
kobj = kobject_create();
// ARM10C 20160109
struct kobject *kobject_create(void)
{
struct kobject *kobj;
// sizeof(struct kobject): 36 bytes, GFP_KERNEL: 0xD0
// kzalloc(36, GFP_KERNEL: 0xD0): kmem_cache#30-oX (struct kobject)
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
// kobj: kmem_cache#30-oX (struct kobject)
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return NULL;
// kobj: kmem_cache#30-oX (struct kobject)
kobject_init(kobj, &dynamic_kobj_ktype);
// ARM10C 20160109
struct kobject *kobject_create(void)
{
struct kobject *kobj;
// sizeof(struct kobject): 36 bytes, GFP_KERNEL: 0xD0
// kzalloc(36, GFP_KERNEL: 0xD0): kmem_cache#30-oX (struct kobject)
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
// kobj: kmem_cache#30-oX (struct kobject)
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return NULL;
// kobj: kmem_cache#30-oX (struct kobject)
kobject_init(kobj, &dynamic_kobj_ktype);
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), &dynamic_kobj_ktype
void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
{
char *err_str;
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj) {
err_str = "invalid kobject pointer!";
goto error;
}
// ktype: &dynamic_kobj_ktype
if (!ktype) {
err_str = "must have a ktype to be initialized properly!\n";
goto error;
}
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized: 0
if (kobj->state_initialized) {
/* do not error out as sometimes we can recover */
printk(KERN_ERR "kobject (%p): tried to init an initialized "
"object, something is seriously wrong.\n", kobj);
dump_stack();
}
// kobj: kmem_cache#30-oX (struct kobject)
kobject_init_internal(kobj);
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject)
static void kobject_init_internal(struct kobject *kobj)
{
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return;
// &kobj->kref: &(kmem_cache#30-oX (struct kobject))->kref
kref_init(&kobj->kref);
// ARM10C 20160109
// &kobj->kref: &(kmem_cache#30-oX (struct kobject))->kref
static inline void kref_init(struct kref *kref)
{
atomic_set(&kref->refcount, 1);
}
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject)
static void kobject_init_internal(struct kobject *kobj)
{
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return;
// &kobj->kref: &(kmem_cache#30-oX (struct kobject))->kref
kref_init(&kobj->kref);
// kref_init에서 한일:
// (&(kmem_cache#30-oX (struct kobject))->kref)->refcount: 1
// &kobj->entry: &(kmem_cache#30-oX (struct kobject))->entry
INIT_LIST_HEAD(&kobj->entry);
// INIT_LIST_HEAD에서 한일:
// (&(kmem_cache#30-oX (struct kobject))->entry)->next: &(kmem_cache#30-oX (struct kobject))->entry
// (&(kmem_cache#30-oX (struct kobject))->entry)->prev: &(kmem_cache#30-oX (struct kobject))->entry
// kobj->state_in_sysfs: (kmem_cache#30-oX (struct kobject))->state_in_sysfs
kobj->state_in_sysfs = 0;
// kobj->state_in_sysfs: (kmem_cache#30-oX (struct kobject))->state_in_sysfs: 0
// kobj->state_add_uevent_sent: (kmem_cache#30-oX (struct kobject))->state_add_uevent_sent
kobj->state_add_uevent_sent = 0;
// kobj->state_add_uevent_sent: (kmem_cache#30-oX (struct kobject))->state_add_uevent_sent: 0
// kobj->state_remove_uevent_sent: (kmem_cache#30-oX (struct kobject))->state_remove_uevent_sent
kobj->state_remove_uevent_sent = 0;
// kobj->state_remove_uevent_sent: (kmem_cache#30-oX (struct kobject))->state_remove_uevent_sent: 0
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized
kobj->state_initialized = 1;
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized: 1
}
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), &dynamic_kobj_ktype
void kobject_init(struct kobject *kobj, struct kobj_type *ktype)
{
char *err_str;
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj) {
err_str = "invalid kobject pointer!";
goto error;
}
// ktype: &dynamic_kobj_ktype
if (!ktype) {
err_str = "must have a ktype to be initialized properly!\n";
goto error;
}
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized: 0
if (kobj->state_initialized) {
/* do not error out as sometimes we can recover */
printk(KERN_ERR "kobject (%p): tried to init an initialized "
"object, something is seriously wrong.\n", kobj);
dump_stack();
}
// kobj: kmem_cache#30-oX (struct kobject)
kobject_init_internal(kobj);
// kobj->ktype: (kmem_cache#30-oX (struct kobject))->ktype, ktype: &dynamic_kobj_ktype
kobj->ktype = ktype;
// kobj->ktype: (kmem_cache#30-oX (struct kobject))->ktype: &dynamic_kobj_ktype
return;
// return
error:
printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str);
dump_stack();
}
EXPORT_SYMBOL(kobject_init);
// ARM10C 20160109
struct kobject *kobject_create(void)
{
struct kobject *kobj;
// sizeof(struct kobject): 36 bytes, GFP_KERNEL: 0xD0
// kzalloc(36, GFP_KERNEL: 0xD0): kmem_cache#30-oX (struct kobject)
kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
// kobj: kmem_cache#30-oX (struct kobject)
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return NULL;
// kobj: kmem_cache#30-oX (struct kobject)
kobject_init(kobj, &dynamic_kobj_ktype);
// kobj: kmem_cache#30-oX (struct kobject)
return kobj;
// return kmem_cache#30-oX (struct kobject)
}
// ARM10C 20160109
// "fs", NULL
struct kobject *kobject_create_and_add(const char *name, struct kobject *parent)
{
struct kobject *kobj;
int retval;
// kobject_create(): kmem_cache#30-oX (struct kobject)
kobj = kobject_create();
// kobj: kmem_cache#30-oX (struct kobject)
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return NULL;
// kobj: kmem_cache#30-oX (struct kobject), parent: NULL, name: "fs"
retval = kobject_add(kobj, parent, "%s", name);
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), parent: NULL, "%s", name: "fs"
int kobject_add(struct kobject *kobj, struct kobject *parent,
const char *fmt, ...)
{
va_list args;
int retval;
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return -EINVAL;
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized: 1
if (!kobj->state_initialized) {
printk(KERN_ERR "kobject '%s' (%p): tried to add an "
"uninitialized object, something is seriously wrong.\n",
kobject_name(kobj), kobj);
dump_stack();
return -EINVAL;
}
// fmt: "%s"
va_start(args, fmt);
// ARM10C 20160109
// _AUPBND: 3
// _bnd("%s",3): 4
//
// #define va_start(args, "%s"):
// (void) ((args) = (((char *) &("%s")) + 4))
#define va_start(ap, A) (void) ((ap) = (((char *) &(A)) + (_bnd (A,_AUPBND))))
// ARM10C 20160109
// #define _bnd("%s", 3):
// (((sizeof ("%s")) + (3)) & (~(3)))
#define _bnd(X, bnd) (((sizeof (X)) + (bnd)) & (~(bnd)))
// ARM10C 20160109
#define va_end(ap) (ap = (va_list) NULL)
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), parent: NULL, "%s", name: "fs"
int kobject_add(struct kobject *kobj, struct kobject *parent,
const char *fmt, ...)
{
va_list args;
int retval;
// kobj: kmem_cache#30-oX (struct kobject)
if (!kobj)
return -EINVAL;
// kobj->state_initialized: (kmem_cache#30-oX (struct kobject))->state_initialized: 1
if (!kobj->state_initialized) {
printk(KERN_ERR "kobject '%s' (%p): tried to add an "
"uninitialized object, something is seriously wrong.\n",
kobject_name(kobj), kobj);
dump_stack();
return -EINVAL;
}
// fmt: "%s"
va_start(args, fmt);
// va_start에서 한일:
// (args): (((char *) &("%s")) + 4): "fs"
// kobj: kmem_cache#30-oX (struct kobject), parent: NULL, fmt: "%s", args: "fs"
retval = kobject_add_varg(kobj, parent, fmt, args);
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), parent: NULL, fmt: "%s", args: "fs"
static int kobject_add_varg(struct kobject *kobj, struct kobject *parent,
const char *fmt, va_list vargs)
{
int retval;
// kobj: kmem_cache#30-oX (struct kobject), fmt: "%s", vargs: "fs"
retval = kobject_set_name_vargs(kobj, fmt, vargs);
int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
va_list vargs)
{
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL
const char *old_name = kobj->name;
// old_name: NULL
char *s;
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL, fmt: "%s"
if (kobj->name && !fmt)
return 0;
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
// kvasprintf(GFP_KERNEL: 0xD0, "%s", "fs"): kmem_cache#30-oX: "fs"
kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
// ARM10C 20160109
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{
unsigned int len;
char *p;
va_list aq;
// ap: "fs"
va_copy(aq, ap);
// ARM10C 20160109
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{
unsigned int len;
char *p;
va_list aq;
// ap: "fs"
va_copy(aq, ap);
// va_copy에서 한일:
// aq: "fs"
// fmt: "%s", aq: "fs"
// vsnprintf(NULL, 0, "%s", "fs"): 2
len = vsnprintf(NULL, 0, fmt, aq);
// ARM10C 20160109
// p: kmem_cache#30-oX, len: 2, fmt: "%s", ap: "fs"
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
unsigned long long num;
char *str, *end;
struct printf_spec spec = {0};
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
// size: 0
if (WARN_ON_ONCE((int) size < 0))
return 0;
// buf: NULL
str = buf;
// str: NULL
// buf: NULL
end = buf + size;
// end: NULL
/* Make sure end is always >= buf */
// end: NULL, buf: NULL
if (end < buf) {
end = ((void *)-1);
size = end - buf;
}
// *fmt: '%'
while (*fmt) {
// fmt: "%s"
const char *old_fmt = fmt;
// old_fmt: "%s"
// fmt: "%s", format_decode("%s", &spec): 2
int read = format_decode(fmt, &spec);
// ARM10C 20160109
// fmt: "%s", &spec
static noinline_for_stack
int format_decode(const char *fmt, struct printf_spec *spec)
{
// fmt: "%s"
const char *start = fmt;
// start: "%s"
/* we finished early by reading the field width */
// spec->type: (&spec)->type: 0, FORMAT_TYPE_WIDTH: 1
if (spec->type == FORMAT_TYPE_WIDTH) {
if (spec->field_width < 0) {
spec->field_width = -spec->field_width;
spec->flags |= LEFT;
}
spec->type = FORMAT_TYPE_NONE;
goto precision;
}
/* we finished early by reading the precision */
// spec->type: (&spec)->type: 0, FORMAT_TYPE_PRECISION: 2
if (spec->type == FORMAT_TYPE_PRECISION) {
if (spec->precision < 0)
spec->precision = 0;
spec->type = FORMAT_TYPE_NONE;
goto qualifier;
}
/* By default */
// spec->type: (&spec)->type: 0, FORMAT_TYPE_NONE: 0
spec->type = FORMAT_TYPE_NONE;
// spec->type: (&spec)->type: 0
// fmt: "%s"
for (; *fmt ; ++fmt) {
// *fmt: '%'
if (*fmt == '%')
break;
// break 수행
}
/* Return the current non-format string */
// fmt: "%s", start: "%s", *fmt: '%'
if (fmt != start || !*fmt)
return fmt - start;
/* Process flags */
// spec->flags: (&spec)->flags
spec->flags = 0;
// spec->flags: (&spec)->flags: 0
while (1) { /* this also skips first '%' */
bool found = true;
// found: true
// fmt: "%s"
++fmt;
// fmt: "s"
// *fmt: 's'
switch (*fmt) {
case '-': spec->flags |= LEFT; break;
case '+': spec->flags |= PLUS; break;
case ' ': spec->flags |= SPACE; break;
case '#': spec->flags |= SPECIAL; break;
case '0': spec->flags |= ZEROPAD; break;
default: found = false;
// found: false
}
// found: false
if (!found)
break;
// break 수행
}
/* get field width */
// spec->field_width: (&spec)->field_width
spec->field_width = -1;
// spec->field_width: (&spec)->field_width: -1
// *fmt: 's', isdigit('s'): 0
if (isdigit(*fmt))
spec->field_width = skip_atoi(&fmt);
else if (*fmt == '*') {
/* it's the next argument */
spec->type = FORMAT_TYPE_WIDTH;
return ++fmt - start;
}
precision:
/* get the precision */
// spec->precision: (&spec)->precision
spec->precision = -1;
// spec->precision: (&spec)->precision: -1
// *fmt: 's'
if (*fmt == '.') {
++fmt;
if (isdigit(*fmt)) {
spec->precision = skip_atoi(&fmt);
if (spec->precision < 0)
spec->precision = 0;
} else if (*fmt == '*') {
/* it's the next argument */
spec->type = FORMAT_TYPE_PRECISION;
return ++fmt - start;
}
}
qualifier:
/* get the conversion qualifier */
// spec->qualifier: (&spec)->qualifier
spec->qualifier = -1;
// spec->qualifier: (&spec)->qualifier: -1
// *fmt: 's', _tolower('s'): 's'
if (*fmt == 'h' || _tolower(*fmt) == 'l' ||
_tolower(*fmt) == 'z' || *fmt == 't') {
spec->qualifier = *fmt++;
if (unlikely(spec->qualifier == *fmt)) {
if (spec->qualifier == 'l') {
spec->qualifier = 'L';
++fmt;
} else if (spec->qualifier == 'h') {
spec->qualifier = 'H';
++fmt;
}
}
}
/* default base */
// spec->base: (&spec)->base
spec->base = 10;
// spec->base: (&spec)->base: 10
// *fmt: 's'
switch (*fmt) {
case 'c':
spec->type = FORMAT_TYPE_CHAR;
return ++fmt - start;
case 's':
// spec->type: (&spec)->type, FORMAT_TYPE_STR: 4
spec->type = FORMAT_TYPE_STR;
// spec->type: (&spec)->type: 4
// fmt: "s", start: "%s"
return ++fmt - start;
// return 2
case 'p':
spec->type = FORMAT_TYPE_PTR;
return fmt - start;
/* skip alnum */
case 'n':
spec->type = FORMAT_TYPE_NRCHARS;
return ++fmt - start;
case '%':
spec->type = FORMAT_TYPE_PERCENT_CHAR;
return ++fmt - start;
/* integer number formats - set up the flags and "break" */
case 'o':
spec->base = 8;
break;
case 'x':
spec->flags |= SMALL;
case 'X':
spec->base = 16;
break;
case 'd':
case 'i':
spec->flags |= SIGN;
case 'u':
break;
default:
spec->type = FORMAT_TYPE_INVALID;
return fmt - start;
}
if (spec->qualifier == 'L')
spec->type = FORMAT_TYPE_LONG_LONG;
else if (spec->qualifier == 'l') {
if (spec->flags & SIGN)
spec->type = FORMAT_TYPE_LONG;
else
spec->type = FORMAT_TYPE_ULONG;
} else if (_tolower(spec->qualifier) == 'z') {
spec->type = FORMAT_TYPE_SIZE_T;
} else if (spec->qualifier == 't') {
spec->type = FORMAT_TYPE_PTRDIFF;
} else if (spec->qualifier == 'H') {
if (spec->flags & SIGN)
spec->type = FORMAT_TYPE_BYTE;
else
spec->type = FORMAT_TYPE_UBYTE;
} else if (spec->qualifier == 'h') {
if (spec->flags & SIGN)
spec->type = FORMAT_TYPE_SHORT;
else
spec->type = FORMAT_TYPE_USHORT;
} else {
if (spec->flags & SIGN)
spec->type = FORMAT_TYPE_INT;
else
spec->type = FORMAT_TYPE_UINT;
}
return ++fmt - start;
}
// ARM10C 20160109
// NULL, 0, fmt: "%s", aq: "fs"
// ARM10C 20160109
// p: kmem_cache#30-oX, len: 2, fmt: "%s", ap: "fs"
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
unsigned long long num;
char *str, *end;
struct printf_spec spec = {0};
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
// size: 0
if (WARN_ON_ONCE((int) size < 0))
return 0;
// buf: NULL
str = buf;
// str: NULL
// buf: NULL
end = buf + size;
// end: NULL
/* Make sure end is always >= buf */
// end: NULL, buf: NULL
if (end < buf) {
end = ((void *)-1);
size = end - buf;
}
// *fmt: '%'
while (*fmt) {
// fmt: "%s"
const char *old_fmt = fmt;
// old_fmt: "%s"
// fmt: "%s", format_decode("%s", &spec): 2
int read = format_decode(fmt, &spec);
// read: 2
// fmt: "%s", read: 2
fmt += read;
// fmt: NULL
// spec.type: 0
switch (spec.type) {
case FORMAT_TYPE_NONE: { // FORMAT_TYPE_NONE: 0
// read: 2
int copy = read;
// copy: 2
// str: NULL, end: NULL
if (str < end) {
if (copy > end - str)
copy = end - str;
memcpy(str, old_fmt, copy);
}
// str: NULL, read: 2
str += read;
// str: 2
break;
// break 수행
}
case FORMAT_TYPE_WIDTH:
spec.field_width = va_arg(args, int);
break;
case FORMAT_TYPE_PRECISION:
spec.precision = va_arg(args, int);
break;
case FORMAT_TYPE_CHAR: {
char c;
if (!(spec.flags & LEFT)) {
while (--spec.field_width > 0) {
if (str < end)
*str = ' ';
++str;
}
}
c = (unsigned char) va_arg(args, int);
if (str < end)
*str = c;
++str;
while (--spec.field_width > 0) {
if (str < end)
*str = ' ';
++str;
}
break;
}
case FORMAT_TYPE_STR:
str = string(str, end, va_arg(args, char *), spec);
break;
case FORMAT_TYPE_PTR:
str = pointer(fmt+1, str, end, va_arg(args, void *),
spec);
while (isalnum(*fmt))
fmt++;
break;
case FORMAT_TYPE_PERCENT_CHAR:
if (str < end)
*str = '%';
++str;
break;
case FORMAT_TYPE_INVALID:
if (str < end)
*str = '%';
++str;
break;
case FORMAT_TYPE_NRCHARS: {
/*
* Since %n poses a greater security risk than
* utility, ignore %n and skip its argument.
*/
void *skip_arg;
WARN_ONCE(1, "Please remove ignored %%n in '%s'\n",
old_fmt);
skip_arg = va_arg(args, void *);
break;
}
default:
switch (spec.type) {
case FORMAT_TYPE_LONG_LONG:
num = va_arg(args, long long);
break;
case FORMAT_TYPE_ULONG:
num = va_arg(args, unsigned long);
break;
case FORMAT_TYPE_LONG:
num = va_arg(args, long);
break;
case FORMAT_TYPE_SIZE_T:
if (spec.flags & SIGN)
num = va_arg(args, ssize_t);
else
num = va_arg(args, size_t);
break;
case FORMAT_TYPE_PTRDIFF:
num = va_arg(args, ptrdiff_t);
break;
case FORMAT_TYPE_UBYTE:
num = (unsigned char) va_arg(args, int);
break;
case FORMAT_TYPE_BYTE:
num = (signed char) va_arg(args, int);
break;
case FORMAT_TYPE_USHORT:
num = (unsigned short) va_arg(args, int);
break;
case FORMAT_TYPE_SHORT:
num = (short) va_arg(args, int);
break;
case FORMAT_TYPE_INT:
num = (int) va_arg(args, int);
break;
default:
num = va_arg(args, unsigned int);
}
str = number(str, end, num, spec);
}
}
// size: 0
if (size > 0) {
if (str < end)
*str = '\0';
else
end[-1] = '\0';
}
/* the trailing null byte doesn't count towards the total */
// str: 2, buf: NULL
return str-buf;
// return 2
}
EXPORT_SYMBOL(vsnprintf);
// ARM10C 20160109
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{
unsigned int len;
char *p;
va_list aq;
// ap: "fs"
va_copy(aq, ap);
// va_copy에서 한일:
// aq: "fs"
// fmt: "%s", aq: "fs"
// vsnprintf(NULL, 0, "%s", "fs"): 2
len = vsnprintf(NULL, 0, fmt, aq);
// len: 11 "kmalloc-192"의 길이
// len: 2
// aq: "fs"
va_end(aq);
#define va_end(ap) (ap = (va_list) NULL)
// ARM10C 20160109
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{
unsigned int len;
char *p;
va_list aq;
// ap: "fs"
va_copy(aq, ap);
// va_copy에서 한일:
// aq: "fs"
// fmt: "%s", aq: "fs"
// vsnprintf(NULL, 0, "%s", "fs"): 2
len = vsnprintf(NULL, 0, fmt, aq);
// len: 11 "kmalloc-192"의 길이
// len: 2
// aq: "fs"
va_end(aq);
// va_end에서 한일:
// aq: NULL
// len: 11, gfp: GFP_NOWAIT: 0
// kmalloc_track_caller(12, GFP_NOWAIT: 0): kmem_cache#30-o0
// len: 2, GFP_KERNEL: 0xD0
p = kmalloc_track_caller(len+1, gfp);
// ARM10C 20160109
// len: 3, GFP_KERNEL: 0xD0
#define kmalloc_track_caller(size, flags) \
__kmalloc_track_caller(size, flags, _RET_IP_)
// ARM10C 20160109
// len: 3, GFP_KERNEL: 0xD0, _RET_IP_
void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
{
struct kmem_cache *s;
void *ret;
// size: 16, KMALLOC_MAX_CACHE_SIZE: 0x2000
if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
return kmalloc_large(size, gfpflags);
// size: 16, gfpflags: GFP_KERNEL: 0xD0
// kmalloc_slab(16, 0xD0): kmem_cache#30
s = kmalloc_slab(size, gfpflags);
// s: kmem_cache#30
// s: kmem_cache#30, ZERO_OR_NULL_PTR(kmem_cache#30): 0
if (unlikely(ZERO_OR_NULL_PTR(s)))
return s;
// s: kmem_cache#30, gfpflags: GFP_KERNEL: 0xD0, _RET_IP_
// slab_alloc(kmem_cache#30, GFP_NOWAIT: 0, _RET_IP_):
// kmem_cache#30-oX
ret = slab_alloc(s, gfpflags, caller);
// ret: kmem_cache#30-o17
/* Honor the call site pointer we received. */
trace_kmalloc(caller, ret, size, s->size, gfpflags);
// ret: kmem_cache#30-o17
return ret;
// return kmem_cache#30-o17
}
// ARM10C 20160109
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap)
{
unsigned int len;
char *p;
va_list aq;
// ap: "fs"
va_copy(aq, ap);
// va_copy에서 한일:
// aq: "fs"
// fmt: "%s", aq: "fs"
// vsnprintf(NULL, 0, "%s", "fs"): 2
len = vsnprintf(NULL, 0, fmt, aq);
// len: 11 "kmalloc-192"의 길이
// len: 2
// aq: "fs"
va_end(aq);
// va_end에서 한일:
// aq: NULL
// len: 11, gfp: GFP_NOWAIT: 0
// kmalloc_track_caller(12, GFP_NOWAIT: 0): kmem_cache#30-o0
// len: 2, GFP_KERNEL: 0xD0
p = kmalloc_track_caller(len+1, gfp);
// p: kmem_cache#30-o0
// p: kmem_cache#30-oX
// p: kmem_cache#30-o0
// p: kmem_cache#30-oX
if (!p)
return NULL;
// p: kmem_cache#30-oX, len: 2, fmt: "%s", ap: "fs"
vsnprintf(p, len+1, fmt, ap);
// vsnprintf에서 한일:
// p: kmem_cache#30-oX: "fs"
// p: kmem_cache#30-o0
// p: kmem_cache#30-oX: "fs"
return p;
// return kmem_cache#30-o0
// return kmem_cache#30-oX: "fs"
}
EXPORT_SYMBOL(kvasprintf);
// ARM10C 20160109
// kobj: kmem_cache#30-oX (struct kobject), fmt: "%s", vargs: "fs"
int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
va_list vargs)
{
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL
const char *old_name = kobj->name;
// old_name: NULL
char *s;
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL, fmt: "%s"
if (kobj->name && !fmt)
return 0;
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: NULL
// GFP_KERNEL: 0xD0, fmt: "%s", vargs: "fs"
// kvasprintf(GFP_KERNEL: 0xD0, "%s", "fs"): kmem_cache#30-oX: "fs"
kobj->name = kvasprintf(GFP_KERNEL, fmt, vargs);
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: kmem_cache#30-oX: "fs"
// kobj->name: (kmem_cache#30-oX (struct kobject))->name: kmem_cache#30-oX: "fs"
if (!kobj->name)
return -ENOMEM;
// 2016/01/09 종료
c68141d..7b4f179 master -> origin/master
Updating c68141d..7b4f179
Fast-forward
fs/dcache.c | 276 ++++++++++++++++++++++-----------------------
fs/inode.c | 458 +++++++++++++++++++++++++++++++++++++-------------------------------------
fs/mount.h | 24 ++++
fs/namespace.c | 626 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------
fs/super.c | 218 ++++++++++++++++++------------------
fs/sysfs/inode.c | 222 ++++++++++++++++++------------------
fs/sysfs/mount.c | 814 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------
include/linux/err.h | 9 ++
include/linux/fs.h | 1 +
include/linux/kernel.h | 1 +
include/linux/list.h | 2 +
include/linux/lockdep.h | 2 +
include/linux/seqlock.h | 126 +++++++++++++++++++++
include/linux/spinlock.h | 4 +
include/linux/spinlock_types.h | 12 ++
include/uapi/asm-generic/errno-base.h | 1 +
16 files changed, 1872 insertions(+), 924 deletions(-)
7b4f179..f8705f2 master -> origin/master
Updating 7b4f179..f8705f2
Fast-forward
README.md | 3 +
fs/namespace.c | 425 ++++++++++++++++++++++++++++++++++++++
include/acpi/actypes.h | 5 +-
include/acpi/platform/acenv.h | 14 ++
include/acpi/platform/aclinux.h | 3 +
include/asm-generic/bitsperlong.h | 1 +
include/linux/ctype.h | 13 ++
include/linux/gfp.h | 1 +
include/linux/kobject.h | 2 +
include/linux/kref.h | 2 +
include/linux/list.h | 2 +
include/linux/slab.h | 4 +
lib/ctype.c | 1 +
lib/kasprintf.c | 25 +++
lib/kobject.c | 118 +++++++++++
lib/vsprintf.c | 91 +++++++-
mm/slub.c | 2 +
17 files changed, 708 insertions(+), 4 deletions(-)