From: Keith Owens <kaos@sgi.com>
To: linux-ia64@vger.kernel.org
Subject: [Linux-ia64] Re: is casting of function descriptor assignments for ia64 ONLY a good idea?
Date: Thu, 03 Jan 2002 08:35:30 +0000 [thread overview]
Message-ID: <marc-linux-ia64-105590698805734@msgid-missing> (raw)
On Wed, 2 Jan 2002 21:46:35 -0800,
Piet/Pete Delaney <piet@sgi.com> wrote:
>SUMMARY:
>
> Keith Owens just pointed out that ia64 function descriptor assignments MUST be cast:
>
> pointer = ((unsigned long *)(&my_printf))[0])
>
> howerver it appears that other platforms MUST NOT be cast.
>
>I was wondering if that a good idea. It seems it might require hacking
>a lot of existing code.
The problem only arises if you want to print or store the location of
the function code. That is very rare, most of the time you just pass
function pointers around and let the compiler handle their format.
Think of a function pointer as an opaque cookie.
>Why is this necessary for just ia64?
Not just ia64, powerpc 64 as well. You are assuming that all pointers
are the same format when that is not guaranteed by the C standard. On
most architectures they are the same, you can convert a function
pointer to a void pointer and back again but it is not defined
behaviour.
On IA64 and PPC64 the function pointer does not reference the function
itself, instead it points to a function descriptor. The function
descriptor contains a pointer to the function code plus additional data
such as a pointer to the global data to be used when the function is
called. This is mandated by the architecture software ABI.
I had to solve this problem for my dynamic syscall patch[1] because the
syscall table points directly to the function code in the kernel, not
to the function descriptor, even on ia64. I define DYNAMIC_SYSCALL_T
and DYNAMIC_SYSCALL_FUNCADDR() which are asm specific. On most
systems, funcaddr is a noop. For i386
#define DYNAMIC_SYSCALL_T long
#define DYNAMIC_SYSCALL_FUNCADDR(f) (DYNAMIC_SYSCALL_T)(f)
but on ia64 it does real work
#define DYNAMIC_SYSCALL_T long long
#define DYNAMIC_SYSCALL_FUNCADDR(f) ({DYNAMIC_SYSCALL_T *fp = (DYNAMIC_SYSCALL_T *)(f); fp[0];})
BTW, the lack of a true descriptor for syscall entries is one reason
why trying to put syscalls in modules is a non-starter. The ia64
syscall handler assumes that all syscall code is in the kernel using
the constant kernel global data pointer, so there is no need to change
the environment on a syscall. But syscalls in modules require a
different environment and there is nowhere to store the extra data in
the syscall table.
[1] http://marc.theaimsgroup.com/?l=linux-kernel&m\x100902118219570&w=2
next reply other threads:[~2002-01-03 8:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-03 8:35 Keith Owens [this message]
2002-01-03 17:11 ` [Linux-ia64] Re: is casting of function descriptor assignments for ia64 ONLY a law
2002-01-03 17:35 ` [Linux-ia64] Re: is casting of function descriptor assignments for ia64 ONLY a good idea? Grant Grundler
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=marc-linux-ia64-105590698805734@msgid-missing \
--to=kaos@sgi.com \
--cc=linux-ia64@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox