Re: Module sections Query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Aug 2, 2008 at 3:24 AM, Asim <linkasim@xxxxxxxxx> wrote:
> Hi,
>
> I'm working on a project related to no-downtime recovery of device drivers.
>
> I wish to allocate a special section in module code and store a copy
> of the .data section that a module can potentially modify. I intend to
> use this section to store a copy of initial .data values that a driver

why must u do this?   when u declare any global variables, or static
var, it is put into a section of its own, and then when GCC generate
the assembly, it will know the relative offset of the variables, and
dereference the memory easily.   if u declare your own section, then
in your assembly u have to calculate the offset DYNAMICALLY.
Alternatively, u can do it STATICALLY, which is to write your own
ELF-generator, (it is called "packers", u can find many in the open
source - eg, UPX) - designing your own sections + offset etc...very
complex.   In fact...I am talking about modifying UPX itself.

> may modify during the course of its operation. I want my section to be
> towards the end and page-aligned. I was wondering what would be my

why the end? many viruses do that, and if u put the executable portion
near the end of a section (eg, .text or .data section), McAfee
immediately flagged it as a virus.

> start and
> end addresses for this section.
>

layout_section() called this:

static long get_offset(unsigned long *size, Elf_Shdr *sechdr)
{
        long ret;

        ret = ALIGN(*size, sechdr->sh_addralign ?: 1);
        *size = ret + sechdr->sh_size;
        return ret;
}

>From header:

typedef struct {
  Elf32_Word    sh_name;
  Elf32_Word    sh_type;
  Elf32_Word    sh_flags;
  Elf32_Addr    sh_addr;
  Elf32_Off     sh_offset;
  Elf32_Word    sh_size;
  Elf32_Word    sh_link;
  Elf32_Word    sh_info;
  Elf32_Word    sh_addralign;
  Elf32_Word    sh_entsize;
} Elf32_Shdr;

typedef struct elf64_shdr {
  Elf64_Word sh_name;           /* Section name, index in string tbl */
  Elf64_Word sh_type;           /* Type of section */
  Elf64_Xword sh_flags;         /* Miscellaneous section attributes */
  Elf64_Addr sh_addr;           /* Section virtual addr at execution */
  Elf64_Off sh_offset;          /* Section file offset */
  Elf64_Xword sh_size;          /* Size of section in bytes */
  Elf64_Word sh_link;           /* Index of another section */
  Elf64_Word sh_info;           /* Additional section information */
  Elf64_Xword sh_addralign;     /* Section alignment */
  Elf64_Xword sh_entsize;       /* Entry size if section holds table */
} Elf64_Shdr;

Which I think is responsible for the alignment of the section in memory.

Two thing:   memory offset and file offset - u have to distinguish
between the two.   fileoffset no alignment, but memory yes.   So in
loading process, some empty spaces have to inserted.

 sechdr->sh_size==> this is physical file offset (from byte 0 of the file).
ret --> ****I THINK**** is trying to round up the current *size value
to the next alignment value, and then add this

> I looked into layout_sections being called from sys_init_module in
> module.c and I'm having trouble understanding it completely. I was
> wondering how I would go about adding a section
> here. Is there any space in the headers between 1 and hdr->e_shnum

not sure what u mean, but I know that the space between the header and
the .text section is limited.....and u cannot keep on increasing the
number of section because of that.

> (where hdr is ELF header)? Or will need to add beyond e_shnum. Kindly
> help.
>
> Regards,
> Asim
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Regards,
Peter Teoh

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux