All of lore.kernel.org
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Data Type used in kernel .
Date: Fri, 23 Dec 2016 19:01:37 +0100	[thread overview]
Message-ID: <20161223180137.GC26271@kroah.com> (raw)
In-Reply-To: <20161223115233.GA13725@osadl.at>

On Fri, Dec 23, 2016 at 11:52:33AM +0000, Nicholas Mc Guire wrote:
> On Fri, Dec 23, 2016 at 06:33:28AM -0500, Pasquier, Thomas wrote:
> > Hello Wasim,
> > 
> > On Fri, Dec 23, 2016 at 6:20 AM, Wasim Akram <wasim7702843288@gmail.com>
> > wrote:
> > 
> > > Hi ,
> > >
> > > I have seen "bool" data type  is used in linux kernel code . Can we
> > > get documentation on data type used in linux kernel development ?
> > >
> > 
> > I think this should be a good start:
> > http://lxr.free-electrons.com/source/include/linux/types.h
> >
> one of the problems though is that there are a number of
> "historic" type systems "left over" in the kernel it seems so
> there actually is a bit of a mess and its not simple to 
> figure out what things really are. For x86_64 I have a list
> of type matches I use for code reading (still not complete)
> which might help.
>  
> x86 64bit:
> ==========
> 
> Type              : equivalent types
> bool              : _Bool,
> char              : signed char, __signed__ char, __s8, s8, int8_t
> unsigned char     : unsigned char, u_char, __u8, u8, unchar, u_int8_t, uint8_t
>                     __ticket_t,
>                     insn_byte_t,
>                     kprobe_opcode_t
> short             : signed short, __signed__ short, s16, int16_t
> unsigned short    : unsigned short, __u16, u16, u_short, ushort, u_int16_t, uint16_t,
>                     __sum16,
>                     umode_t,
>                     __ticketpair_t,
>                     apm_eventinfo_t,
>                     apm_event_t,
>                     Elf32_Sword,
>                     Elf32_Half,
>                     Elf64_Half,
>                     Elf64_SHalf,
>                     __kernel_sa_family_t,
>                     __kernel_gid16_t, gid16_t,
>                     __kernel_uid16_t, uid16_t,
>                     __kernel_old_uid_t, old_uid_t,
>                     __kernel_old_gid_t, old_gid_t,
>                     arch cond: __le16/__be16
> int               : signed int, __signed__ int, __s32, s32, int32_t,  s_int32_t      
>                     Elf64_Sword,
>                     Elf64_Sxword,
>                     key_serial_t,
>                     insn_value_t,
>                     __kernel_daddr_t, daddr_t,
>                     __kernel_ipc_pid_t, pid_t,
>                     __kernel_pid_t,
>                     __kernel_mqd_t, mqd_t,
>                     __kernel_key_t, key_t,
>                     __kernel_timer_t timer_t,
> unsigned int      : unsigned, unsigned int, __u32, u32, u_int32_t, uInt, u_int, uint, uint32_t,
>                     __wsum,
>                     nlink_t,
>                     gfp_t,
>                     fmode_t,
>                     oom_flags_t,
>                     isolate_mode_t,
>                     Elf32_Addr,
>                     Elf32_Off,
>                     Elf32_Word,
>                     Elf64_Word,
>                     key_perm_t,
>                     insn_attr_t,
>                     sk_buff_data_t,
>                     sctp_assoc_t.
>                     __kernel_dev_t, dev_t, 
>                     __kernel_uid32_t, uid_t, projid_t, qid_t
>                     __kernel_gid32_t, gid_t,
>                     __kernel_uid_t, 
>                     __kernel_gid_t,
>                     __kernel_mode_t, mode_t,
>                     arch cond: __le32/__be32
> long              : signed long, __kernel_long_t, 
>                     __kernel_suseconds_t, suseconds_t,
>                     __kernel_ssize_t, ssize_t,
>                     __kernel_ptrdiff_t,
>                     __kernel_off_t, off_t,
>                     __kernel_time_t, time_t,
>                     __kernel_clock_t, clock_t,
> unsigned long     : __kernel_ulong_t, u_long, ulong
>                     uintptr_t,
>                     sector_t,
>                     blkcnt_t,
>                     irq_hw_number_t,
>                     pteval_t,
>                     pmdval_t,
>                     pudval_t,
>                     pgdval_t,
>                     pgprotval_t,
>                     vm_flags_t,
>                     elf_greg_t,
>                     cputime_t,
>                     old_sigset_t,
>                     aio_context_t,
>                     flow_compare_t,
>                     __kernel_ino_t, ino_t 
>                     __kernel_old_dev_t
>                     __kernel_size_t. size_t,
>                     arch cond: __le64/__be64
> long long         : signed long long, __signed__ long long, __s64, s64, int64_t
>                     time64_t,
>                     qsize_t,
>                     __kernel_loff_t, loff_t,
> unsigned long long: u64, __u64, uint64_t, u_int64_t
>                     dma_addr_t,
>                     cycles_t,
>                     phys_addr_t, resource_size_t
>                     cycle_t,
>                     Elf64_Addr,
>                     Elf64_Off,
>                     Elf64_Xword,
>                     cputime64_t,
>                     netdev_features_t

That's crazy.  Just use the data types that the LDD book says to use for
in-kernel code:
	u8, u16, u32, u64, s8, s16, s32, s64, int, bool
and if the data crosses the user/kernel boundry, use the correct ones
for that (__ in front, no int).

You can use others, but you better know what you are doing if you do :)

Hope this helps,

greg k-h

  reply	other threads:[~2016-12-23 18:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23 11:20 Data Type used in kernel Wasim Akram
2016-12-23 11:33 ` Pasquier, Thomas
2016-12-23 11:52   ` Nicholas Mc Guire
2016-12-23 18:01     ` Greg KH [this message]
2016-12-24  8:06       ` Nicholas Mc Guire
2016-12-24  9:37         ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161223180137.GC26271@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.