require #define NEED_GLOBAL_ENV for files that need the global register variable
A message that is not in the archive (sent off-list or not yet received): 5692464.1280361277887491249.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines
Wouldn't it be better to just put this in
dyngen-exec.h? AFAICT there's a direct correlation betweenNEED_GLOBAL_ENVand #include "exec.h".True, see cover letter in 0/4. I was told to make each file request explicitly the global variable though. So I'd have to leave the #ifdef even if I moved it into
dyngen-exec.h.Well, I only said I'd rename global 'env' to '
global_reg_env', not something about each file requesting it. ButNEED_GLOBAL_ENVwasn't so bad idea in my opinion.
It doesn't matter what's the name of the global. What matters is whether it's defined at all. For this reason it's bad to bury it in dyngen-exec.h which is included only indirectly. It's better to leave it in all */exec.h files as Paul explained---and I agree with him.
I also gave reason why unpoisoning env globally is not a problem at all. For target-dependent files, they did not (and do not) poison anything, so my first patch series didn't change anything WRT current QEMU sources. exec.h always includes cpu.h, so there's no way exec.h can be included by mistake in a target-independent file. I can make exec.h error out if NEED_CPU_H is not defined, but I think it's a worthless complication.
So, can someone please apply patches 1 to 3 of this series so that we can move on?
Paolo
Quoted 8 lines · Paolo Bonzini
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Wouldn't it be better to just put this in
dyngen-exec.h? AFAICT there's a direct correlation betweenNEED_GLOBAL_ENVand #include "exec.h".True, see cover letter in 0/4. I was told to make each file request explicitly the global variable though. So I'd have to leave the #ifdef even if I moved it into
dyngen-exec.h.
Quoted 5 lines
Quoted 3 lines
Well, I only said I'd rename global 'env' to '
global_reg_env', not something about each file requesting it. ButNEED_GLOBAL_ENVwasn't so bad idea in my opinion.It doesn't matter what's the name of the global.
Yes it does. Unfortunately, 'env' is a name which is used for other purposes than the global register variable pointing to CPUState. Any of these uses could accidentally refer to global 'env'. Also one bug was where the function had parameter 'env1', but some code inside still used 'env'. These kind of bugs can be avoided by simply renaming 'env' to less collision prone name.
Quoted 5 lines
What matters is
whether it's defined at all. For this reason it's bad to bury it indyngen-exec.hwhich is included only indirectly. It's better to leave it in all*/exec.hfiles as Paul explained---and I agree with him.
Fine by me too.
Quoted 7 lines
I also gave reason why unpoisoning env globally is not a problem at all. For target-dependent files, they did not (and do not) poison anything, so my first patch series didn't change anything WRT current QEMU sources. exec.h always includes
cpu.h, so there's no wayexec.hcan be included by mistake in a target-independent file. I can makeexec.herror out ifNEED_CPU_His not defined, but I think it's a worthless complication.
I still maintain that 'env' may not be unpoisoned until the name is less likely to invite accidents.
Quoted 3 lines
So, can someone please apply patches 1 to 3 of this series so that we can move on?
I think they are nice cleanups regardless of the approach for 'env'. If nobody has any objections, I'll apply them on Saturday.
Quoted 2 lines · Blue Swirl
I still maintain that 'env' may not be unpoisoned until the name is less likely to invite accidents.
The *global* env is still unavailable (i.e. no difference WRT poisoning), by virtue of being defined in exec.h which is not available unless -DNEED_CPU_H is defined.
So:
| before | after
------------+---------------------------------+--------------------------
NEED_CPU_H | env not poisoned, global env | same
| available iff exec.h included |
------------+---------------------------------+--------------------------
!NEED_CPU_H | env poisoned; CPUState | env not poisoned;
| not available, so exec.h cannot | exec.h requires cpu.h
| be included | so it cannot be includedPaolo
Quoted 11 lines · Paolo Bonzini
Quoted 3 lines · Blue Swirl
I still maintain that 'env' may not be unpoisoned until the name is less likely to invite accidents.
The *global* env is still unavailable (i.e. no difference WRT poisoning), by virtue of being defined in
exec.hwhich is not available unless -DNEED_CPU_H is defined.So:
Quoted 8 lines
| before | after
------------+---------------------------------+--------------------------NEED_CPU_H| env not poisoned, global env | same
| available iffexec.hincluded |
------------+---------------------------------+--------------------------
!NEED_CPU_H | env poisoned; CPUState | env not poisoned;| not available, so exec.h cannot | exec.h requires cpu.h | be included | so it cannot be included
But why would it be necessary to unpoison 'env' for the lower right case? Poisoning protects against accidents (in addition to exec.h thing) and there are no downsides.
Quoted 16 lines · Blue Swirl
Quoted 6 lines · Paolo Bonzini
The *global* env is still unavailable (i.e. no difference WRT poisoning), by virtue of being defined in
exec.hwhich is not available unless -DNEED_CPU_H is defined.So:
Quoted 8 lines
| before | after
------------+---------------------------------+--------------------------NEED_CPU_H | env not poisoned, global env | same | available iff exec.h included | ------------+---------------------------------+-------------------------- !NEED_CPU_H | env poisoned; CPUState | env not poisoned; | not available, so exec.h cannot | exec.h requires cpu.h | be included | so it cannot be included
Quoted 3 lines
But why would it be necessary to unpoison 'env' for the lower right case? Poisoning protects against accidents (in addition to
exec.hthing) and there are no downsides.
Because double protection is useless. Two warnings may be better than one, but we're talking about compilation errors and two errors do not achieve anything more than one error. Plus, the policy for code using the global `env' is clear and is not going to change, and including exec.h outside cpu-exec.c/op_helper.c would be spotted instantly during code review.
And the downside, of course, is that you're holding up a patch to improve QEMU's type-safety.
If you want to poison env on all files that do not include exec.h that's another story. I think it's a good idea, but it's not what the current code does. So my pending patches would not make anything worse compared to the status quo, and it's something that can be done after my existing patches go in.
Besides, I'm on vacation and I try to enjoy nature more than hacking for these three weeks. :) So if you want me to rebase/resend, that's half hour work and I'll do it gladly, otherwise I'll pass the ball.
Paolo