[PATCH] module: Remove a extra null character at the top of module->strtab.

2012-11-27 Thread sat
From: Satoru Takeuchi 

There is a extra null character('\0') at the top of module->strtab for
each module. Commit 59ef28b introduced this bug and this patch fixes it.

Live dump log of the current linus git kernel(HEAD is 2844a4870):

crash> mod | grep loop
a01db0a0  loop 16689  (not loaded)  [CONFIG_KALLSYMS]
crash> module.core_symtab a01db0a0
  core_symtab = 0xa01db320crash> rd 0xa01db320 12
a01db320:  00550001    U...
a01db330:   000200740002   t...
a01db340:  a01d8000 0038   8...
a01db350:  001a0064000e a01daeb0   d...
a01db360:  00a0 000200740019   t...
a01db370:  a01d8068 001b   h...
crash> module.core_strtab a01db0a0
  core_strtab = 0xa01dbb30 ""
crash> rd 0xa01dbb30 4
a01dbb30:  615f70616d6b 66780063696d6f74   ..kmap_atomic.xf
a01dbb40:  73636e75665f7265 72665f646e696600   er_funcs.find_fr


We expect Just first one byte of '\0', but actually first two bytes
are '\0'. Here is The relationship between symtab and strtab.

symtab_idx  strtab_idx  symbol
---
0   0x1 "\0" # startab_idx should be 0
1   0x2 "kmap_atomic"
2   0xe "xfer_funcs"
3   0x19"find_fr..."

By applying this patch, it becomes as follows.

symtab_idx  strtab_idx  symbol
---
0   0x0 "\0"# extra byte is removed
1   0x1 "kmap_atomic"
2   0xd "xfer_funcs"
3   0x18"find_fr..."

Signed-off-by: Satoru Takeuchi 
Cc: Masaki Kimura 
Cc: Rusty Russell 
Cc: Greg Kroah-Hartman 
---
 kernel/module.c |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 6e48c3a..7af5d5d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2282,7 +2282,7 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
Elf_Shdr *symsect = info->sechdrs + info->index.sym;
Elf_Shdr *strsect = info->sechdrs + info->index.str;
const Elf_Sym *src;
-   unsigned int i, nsrc, ndst, strtab_size;
+   unsigned int i, nsrc, ndst, strtab_size = 0;
 
/* Put symbol section at end of init part of module. */
symsect->sh_flags |= SHF_ALLOC;
@@ -2293,9 +2293,6 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
src = (void *)info->hdr + symsect->sh_offset;
nsrc = symsect->sh_size / sizeof(*src);
 
-   /* strtab always starts with a nul, so offset 0 is the empty string. */
-   strtab_size = 1;
-
/* Compute total space required for the core symbols' strtab. */
for (ndst = i = 0; i < nsrc; i++) {
if (i == 0 ||
@@ -2337,7 +2334,6 @@ static void add_kallsyms(struct module *mod, const struct 
load_info *info)
mod->core_symtab = dst = mod->module_core + info->symoffs;
mod->core_strtab = s = mod->module_core + info->stroffs;
src = mod->symtab;
-   *s++ = 0;
for (ndst = i = 0; i < mod->num_symtab; i++) {
if (i == 0 ||
is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
-- 1.7.2.5 

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] module: Remove a extra null character at the top of module-strtab.

2012-11-27 Thread sat
From: Satoru Takeuchi takeuchi_sat...@jp.fujitsu.com

There is a extra null character('\0') at the top of module-strtab for
each module. Commit 59ef28b introduced this bug and this patch fixes it.

Live dump log of the current linus git kernel(HEAD is 2844a4870):

crash mod | grep loop
a01db0a0  loop 16689  (not loaded)  [CONFIG_KALLSYMS]
crash module.core_symtab a01db0a0
  core_symtab = 0xa01db320crash rd 0xa01db320 12
a01db320:  00550001    U...
a01db330:   000200740002   t...
a01db340:  a01d8000 0038   8...
a01db350:  001a0064000e a01daeb0   d...
a01db360:  00a0 000200740019   t...
a01db370:  a01d8068 001b   h...
crash module.core_strtab a01db0a0
  core_strtab = 0xa01dbb30 
crash rd 0xa01dbb30 4
a01dbb30:  615f70616d6b 66780063696d6f74   ..kmap_atomic.xf
a01dbb40:  73636e75665f7265 72665f646e696600   er_funcs.find_fr


We expect Just first one byte of '\0', but actually first two bytes
are '\0'. Here is The relationship between symtab and strtab.

symtab_idx  strtab_idx  symbol
---
0   0x1 \0 # startab_idx should be 0
1   0x2 kmap_atomic
2   0xe xfer_funcs
3   0x19find_fr...

By applying this patch, it becomes as follows.

symtab_idx  strtab_idx  symbol
---
0   0x0 \0# extra byte is removed
1   0x1 kmap_atomic
2   0xd xfer_funcs
3   0x18find_fr...

Signed-off-by: Satoru Takeuchi takeuchi_sat...@jp.fujitsu.com
Cc: Masaki Kimura masaki.kimura...@hitachi.com
Cc: Rusty Russell ru...@rustcorp.com.au
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
---
 kernel/module.c |6 +-
 1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 6e48c3a..7af5d5d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2282,7 +2282,7 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
Elf_Shdr *symsect = info-sechdrs + info-index.sym;
Elf_Shdr *strsect = info-sechdrs + info-index.str;
const Elf_Sym *src;
-   unsigned int i, nsrc, ndst, strtab_size;
+   unsigned int i, nsrc, ndst, strtab_size = 0;
 
/* Put symbol section at end of init part of module. */
symsect-sh_flags |= SHF_ALLOC;
@@ -2293,9 +2293,6 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
src = (void *)info-hdr + symsect-sh_offset;
nsrc = symsect-sh_size / sizeof(*src);
 
-   /* strtab always starts with a nul, so offset 0 is the empty string. */
-   strtab_size = 1;
-
/* Compute total space required for the core symbols' strtab. */
for (ndst = i = 0; i  nsrc; i++) {
if (i == 0 ||
@@ -2337,7 +2334,6 @@ static void add_kallsyms(struct module *mod, const struct 
load_info *info)
mod-core_symtab = dst = mod-module_core + info-symoffs;
mod-core_strtab = s = mod-module_core + info-stroffs;
src = mod-symtab;
-   *s++ = 0;
for (ndst = i = 0; i  mod-num_symtab; i++) {
if (i == 0 ||
is_core_symbol(src+i, info-sechdrs, info-hdr-e_shnum)) {
-- 1.7.2.5 

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Sat.
here is a snip in 0.11 version linux , 
in linux/init/main.c


179 if (!(pid=fork())) {
180 close(0);
181 if (open( "/etc/rc",O_RDONLY,0))
182 _exit(1);
183 execve( "/bin/sh",argv_rc,envp_rc); 
184 _exit(2);
185 }

natually, the code from 180 to 184 is runned by the new process, what
I can understand is why the new process know that the next code will
run is close(0) and why it know It will end at line 184 ?

so ,I feel that there should be some connection between  them . but
what the relationship in depth is ?

thanks your help :) 


2005/9/6, Dirk Gerdes <[EMAIL PROTECTED]>:
> There is no connection between a child an its parent.
> The child only gets a copy of the code.
> If there were a pointer to a child or to the parent, you wouldn't need any
> signals.
> The processes could communicate directly.
> 
> regards
> 
> - Original Message -
> From: "Sat." <[EMAIL PROTECTED]>
> To: 
> Sent: Tuesday, September 06, 2005 11:15 AM
> Subject: what will connect the fork() with its following code ? a simple
> example below:
> 
> 
> > if(!(pid=fork())){
> > ..
> > printk("in child process");
> > ..
> > }else{
> > .
> > printk("in father process");
> > .
> > }
> >
> > this is a classical example, when the fork() system call runs, it will
> > build a new process and active it . while the schedule() select the
> > new process it will run. this is rather normal.
> >
> > but there is always a confusion in my minds.
> > because , sys_fork() only copies father process and configure some new
> > values., and do nothing . so the bridge  between the new process and
> > its following code, printk("in child process"), seems disappear . so I
> > always believe that the new process should have a pointer which point
> > the code "printk("in child process");". except this , there are not
> > any connection between them ?
> >
> > very confused :(
> >
> > any help will  appreciate  !
> >
> >
> >
> > --
> > Sat.
> > -
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to [EMAIL PROTECTED]
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/
> >
> 
> 


-- 
Sat.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: what will connect the fork() with its following code ? a simple example below:

2005-09-06 Thread Sat.
here is a snip in 0.11 version linux , 
in linux/init/main.c


179 if (!(pid=fork())) {
180 close(0);
181 if (open( /etc/rc,O_RDONLY,0))
182 _exit(1);
183 execve( /bin/sh,argv_rc,envp_rc); 
184 _exit(2);
185 }

natually, the code from 180 to 184 is runned by the new process, what
I can understand is why the new process know that the next code will
run is close(0) and why it know It will end at line 184 ?

so ,I feel that there should be some connection between  them . but
what the relationship in depth is ?

thanks your help :) 


2005/9/6, Dirk Gerdes [EMAIL PROTECTED]:
 There is no connection between a child an its parent.
 The child only gets a copy of the code.
 If there were a pointer to a child or to the parent, you wouldn't need any
 signals.
 The processes could communicate directly.
 
 regards
 
 - Original Message -
 From: Sat. [EMAIL PROTECTED]
 To: linux-kernel@vger.kernel.org
 Sent: Tuesday, September 06, 2005 11:15 AM
 Subject: what will connect the fork() with its following code ? a simple
 example below:
 
 
  if(!(pid=fork())){
  ..
  printk(in child process);
  ..
  }else{
  .
  printk(in father process);
  .
  }
 
  this is a classical example, when the fork() system call runs, it will
  build a new process and active it . while the schedule() select the
  new process it will run. this is rather normal.
 
  but there is always a confusion in my minds.
  because , sys_fork() only copies father process and configure some new
  values., and do nothing . so the bridge  between the new process and
  its following code, printk(in child process), seems disappear . so I
  always believe that the new process should have a pointer which point
  the code printk(in child process);. except this , there are not
  any connection between them ?
 
  very confused :(
 
  any help will  appreciate  !
 
 
 
  --
  Sat.
  -
  To unsubscribe from this list: send the line unsubscribe linux-kernel in
  the body of a message to [EMAIL PROTECTED]
  More majordomo info at  http://vger.kernel.org/majordomo-info.html
  Please read the FAQ at  http://www.tux.org/lkml/
 
 
 


-- 
Sat.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: when or where can the case occur in "linux kernel development " about "kernel preemption"?

2005-08-27 Thread Sat.
2005/8/27, Christopher Friesen <[EMAIL PROTECTED]>:
> Sat. wrote:
> > the case about kernel preemption as follow :
> >
> > the book said "when a process that has a higher priority than the
> > currenty running process is awakened ".
> >
> > but I can think about when such case can occur , could you give me an 
> > example ?
> 
> There may be others, but one common case is when a hardware interrupt
> causes the higher priority process to become runnable.  Some examples of
> this would be a network packet arriving, or the expiry of a hardware timer.
> 
> Chris
> 

unfortunately, I cannot agree with you , normally ,when the kernel
runs in interrupt context , the schedule() should not be invoked 
--my views .

then,could anyone  give me a definite example about network like above
or anything else to eluminate  this , ok?

thanks !

-- 
Sat.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: when or where can the case occur in linux kernel development about kernel preemption?

2005-08-27 Thread Sat.
2005/8/27, Christopher Friesen [EMAIL PROTECTED]:
 Sat. wrote:
  the case about kernel preemption as follow :
 
  the book said when a process that has a higher priority than the
  currenty running process is awakened .
 
  but I can think about when such case can occur , could you give me an 
  example ?
 
 There may be others, but one common case is when a hardware interrupt
 causes the higher priority process to become runnable.  Some examples of
 this would be a network packet arriving, or the expiry of a hardware timer.
 
 Chris
 

unfortunately, I cannot agree with you , normally ,when the kernel
runs in interrupt context , the schedule() should not be invoked 
--my views .

then,could anyone  give me a definite example about network like above
or anything else to eluminate  this , ok?

thanks !

-- 
Sat.
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/