Re: how to tell if a process is 64-bit

2017-09-14 Thread Eduardo Horvath
On Thu, 14 Sep 2017, Martin Husemann wrote:

> On Thu, Sep 14, 2017 at 02:31:29PM +0200, Thomas Klausner wrote:
> > kp = kvm_getproc2(kvmp, KERN_PROC_PID, pid, sizeof(*kp), );
> > if (res != 1)
> > exit(1);
> 
>   if (kp->p_flag & P_32)
>   printf("it is a 32bit process\n");
> 
> Unless you are running with a 32bit kernel, then you'll never see that
> flag (but also the question does not make sense).

In theory you could run 64-bit processes on a 32-bit kernel on CPUs that 
have disjoint user and kernel address spaces, like sparcv9.  In that case 
it would make sense to use the P_32 flag to distinguish processes with 
32-bit address spaces from those with 64-bit address spaces.

However, it would be a lot of work and probably not worth the effort since 
the kernel would be limited to 32-bits of data structures such as file 
descriptors and uvm spaces and be hard pressed to keep up with the demands 
of 64-bit address spaces.  (And implementing copyin/copyout routines would 
be fun.)

So yes, at the moment setting the P_32 flag on every process running on a 
32-bit kernel seems like a waste of CPU cycles.

Eduardo



Re: how to tell if a process is 64-bit

2017-09-14 Thread Martin Husemann
On Thu, Sep 14, 2017 at 02:31:29PM +0200, Thomas Klausner wrote:
>   kp = kvm_getproc2(kvmp, KERN_PROC_PID, pid, sizeof(*kp), );
>   if (res != 1)
>   exit(1);

if (kp->p_flag & P_32)
printf("it is a 32bit process\n");

Unless you are running with a 32bit kernel, then you'll never see that
flag (but also the question does not make sense).

Martin


Re: how to tell if a process is 64-bit

2017-09-14 Thread Thomas Klausner
On Sat, Sep 09, 2017 at 05:58:53AM +1000, Matthew Green wrote:
> > In a cross-platform process utility tool the question came up how to
> > decide if a process is 64-bit.
> > 
> > https://github.com/giampaolo/psutil/issues/1102
> > 
> > What's the best answer for NetBSD?
> 
> in C:
> 
> internally, just check #ifdef _LP64.
> externally, kvm_getprocs() with KERN_PROC_PID.
> 
> in other languages?  don't ask me.

I'm asking for a python frontend to the C one.

I came up with this fragment:

#include 
#include 
#include 

int main(int argc, char *argv[]) {
int pid, res;
struct kinfo_proc2 *kp;
kvm_t *kvmp = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, NULL);
if (kvmp == NULL)
exit(1);
pid = atoi(argv[1]);
kp = kvm_getproc2(kvmp, KERN_PROC_PID, pid, sizeof(*kp), );
if (res != 1)
exit(1);
kvm_close(kvmp);
}


Which part of the structure can I check to find out 32-bitness?

Thanks,
 Thomas


re: how to tell if a process is 64-bit

2017-09-10 Thread matthew green
Thor Lancelot Simon writes:
> On Sun, Sep 10, 2017 at 03:29:22PM +, paul.kon...@dell.com wrote:
> > 
> > MIPS has four ABIs, if you include "O64".  Whether a particular OS allows
> > all four concurrently is another matter; it isn't clear that would make
> > sense.  Mixing "O" and "N" ABIs is rather messy.
> > 
> > Would you call N32 a 64-bit ABI?  It has 64 bit registers, so if a value
> > is passed to the kernel in a register it comes across as 64 bits.  But it
> > has 32 bit addresses.
> 
> I wouldn't, because if an address is passed to the kernel, it comes across
> as 32 bits.  But what _do_ we do on modern, 32-bit MIPS?  Are we still O32?
> It does kind of look like it -- all our 32-bit MIPS ports' sets files seem
> to be linked to ../../../shared/mipsel/ which must be O32 since it is also
> used for the pmax sets.

as i mentioned earlier in this thread, our mips64 defaults to n32
userland for everything except kvm-only using utils (that all need
to be fixed.)

o32, n32 and n64 all are supported, though n64 dynamic is currently
broken for some reason i haven't looked closely at.

any mips port without "64" in it is o32-only, because it's built to
only support a 32 bit register-size CPU.


.mrg.


Re: how to tell if a process is 64-bit

2017-09-10 Thread Thor Lancelot Simon
On Sun, Sep 10, 2017 at 03:29:22PM +, paul.kon...@dell.com wrote:
> 
> MIPS has four ABIs, if you include "O64".  Whether a particular OS allows
> all four concurrently is another matter; it isn't clear that would make
> sense.  Mixing "O" and "N" ABIs is rather messy.
> 
> Would you call N32 a 64-bit ABI?  It has 64 bit registers, so if a value
> is passed to the kernel in a register it comes across as 64 bits.  But it
> has 32 bit addresses.

I wouldn't, because if an address is passed to the kernel, it comes across
as 32 bits.  But what _do_ we do on modern, 32-bit MIPS?  Are we still O32?
It does kind of look like it -- all our 32-bit MIPS ports' sets files seem
to be linked to ../../../shared/mipsel/ which must be O32 since it is also
used for the pmax sets.

-- 
  Thor Lancelot Simont...@panix.com

  "We cannot usually in social life pursue a single value or a single moral
   aim, untroubled by the need to compromise with others."  - H.L.A. Hart


Re: how to tell if a process is 64-bit

2017-09-10 Thread Paul.Koning

> On Sep 10, 2017, at 10:31 AM, Thor Lancelot Simon  wrote:
> 
> On Fri, Sep 08, 2017 at 07:38:24AM -0400, Mouse wrote:
>>> In a cross-platform process utility tool the question came up how to
>>> decide if a process is 64-bit.
>> 
>> First, I have to ask: what does it mean to say that a particular
>> process is - or isn't - 64-bit?
> 
> I think the only simple answer is "it is 64-bit in the relevant sense if
> it uses the platform's 64-bit ABI for interaction with the kernel".
> 
> This actually raises a question for me about MIPS: do we have another
> process flag to indicate O32 vs. N32, or can we simply not run O32
> executables on 64-bit or N32 kernels (surely we don't use the O32 ABI
> for all kernel interaction by 32-bit processes)?

MIPS has four ABIs, if you include "O64".  Whether a particular OS allows
all four concurrently is another matter; it isn't clear that would make
sense.  Mixing "O" and "N" ABIs is rather messy.

Would you call N32 a 64-bit ABI?  It has 64 bit registers, so if a value
is passed to the kernel in a register it comes across as 64 bits.  But it
has 32 bit addresses.

paul



Re: how to tell if a process is 64-bit

2017-09-10 Thread Kamil Rytarowski
On 10.09.2017 16:31, Thor Lancelot Simon wrote:
> On Fri, Sep 08, 2017 at 07:38:24AM -0400, Mouse wrote:
>>> In a cross-platform process utility tool the question came up how to
>>> decide if a process is 64-bit.
>>
>> First, I have to ask: what does it mean to say that a particular
>> process is - or isn't - 64-bit?
> 
> I think the only simple answer is "it is 64-bit in the relevant sense if
> it uses the platform's 64-bit ABI for interaction with the kernel".
> 
> This actually raises a question for me about MIPS: do we have another
> process flag to indicate O32 vs. N32, or can we simply not run O32
> executables on 64-bit or N32 kernels (surely we don't use the O32 ABI
> for all kernel interaction by 32-bit processes)?
> 
> Thor
> 

From a debugger pointer of view it's useful to know ABI and emulation
name of a running application.

This is also useful in core(5) files.

On Linux there is a problem to guess ABI and there is guessing (mostly
assuming the host one).

However any changes in this field are premature from my side. I need to
get elementary features to work properly.



signature.asc
Description: OpenPGP digital signature


Re: how to tell if a process is 64-bit

2017-09-10 Thread Thor Lancelot Simon
On Fri, Sep 08, 2017 at 07:38:24AM -0400, Mouse wrote:
> > In a cross-platform process utility tool the question came up how to
> > decide if a process is 64-bit.
> 
> First, I have to ask: what does it mean to say that a particular
> process is - or isn't - 64-bit?

I think the only simple answer is "it is 64-bit in the relevant sense if
it uses the platform's 64-bit ABI for interaction with the kernel".

This actually raises a question for me about MIPS: do we have another
process flag to indicate O32 vs. N32, or can we simply not run O32
executables on 64-bit or N32 kernels (surely we don't use the O32 ABI
for all kernel interaction by 32-bit processes)?

Thor


Re: how to tell if a process is 64-bit

2017-09-09 Thread Martin Husemann
On Sat, Sep 09, 2017 at 07:41:55AM +1000, matthew green wrote:
> eeh - matt@ fixed mount compat a few years ago, as well as a lot
> of the remaining edge cases we'd never gotten to.  it was necessary
> to run full n32 userland on n64 kernel (we still build all the
> kvm-on-running-kernel-using programs as n64.)  so that generally
> works fine now..

There are a few minor things that don't quite work (the ioctls used
by raidctl for example), but otherwise a GENERIC sparc64 kernel
fully works with a stock sparc userland (modulo the KVM things matthew
mentioned).

Martin


RE: how to tell if a process is 64-bit

2017-09-08 Thread Terry Moore
Hi,

> In a cross-platform process utility tool the question came up how to
decide if a process is 64-bit.
>
> https://github.com/giampaolo/psutil/issues/1102
>
> What's the best answer for NetBSD?

If I understand correctly, you want psutil-based scripts -- which seem to 
be written in Python -- to be able to ask "is-64" about other processes? 
I suppose you are therefore interested in knowing the base ISA of a given 
process from outside the process?

(As others have mentioned, you might instead, or additionally, be interested

in the emulation that's in use.)

Are you looking for the system calls, or the python equivalents?

Can you clarify?

Best regards,
--Terry




re: how to tell if a process is 64-bit

2017-09-08 Thread matthew green
> > In addition to amd64/i386, it occurs to me that sparc64/sparc32 is
> > another case; IIRC it's possible to take sparc64 hardware and build a
> > (special? not sure) kernel that runs sparc32 userland.  I've never
> > tried it; I don't know whether sparc32 and sparc64 are as freely
> > mixable at runtime as amd64 and i386 are under amd64 kernels.
> 
> Yes, that's what compat/netbsd32 is for.  (Of course, there are still a 
> few things like mount I never bothered to get working across ABIs.)

there are a few supported cases here:  32 bit kernel on 64 bit cpu
(32 bit userland only).  64 bit kernel with either size userland.

eeh - matt@ fixed mount compat a few years ago, as well as a lot
of the remaining edge cases we'd never gotten to.  it was necessary
to run full n32 userland on n64 kernel (we still build all the
kvm-on-running-kernel-using programs as n64.)  so that generally
works fine now..


.mrg.


Re: how to tell if a process is 64-bit

2017-09-08 Thread Mouse
> That's why I asked "what does 'is 64-bit' mean".  Your previous reference to$

Any particular reason for the paragraph-length line?

Manually repairing it (and trimming to the part I'm replying to),

> [...] the question "does this program use 64 bit addresses".  There
> are at least two other possible questions: (a) does this program have
> access to 64 bit registers, and (b) can this program do operations
> such as arithmetic on 64 bit integers.

You would be hard-pressed to find a platform on which (b) is false (and
I'm not restricting that to NetBSD-supporting platforms, though I think
I would have to restrict it to devices that were designed to be
general-purpose computers).  Even things like the tiny little
MC68HC908QY4 8-bit microcontrollers in 16-pin DIP packages I've
currently lost my tube of can do 64-bit arithmetic.

Not fast (they don't do _anything_ fast), and not in single
instructions, but so what?  Even a sparc64 machine can't do a
general-purpose 64-bit add in a single instruction unless both inputs
are already in registers and leaving the output in a register is
acceptable.

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Re: how to tell if a process is 64-bit

2017-09-08 Thread Eduardo Horvath
On Fri, 8 Sep 2017, Mouse wrote:

> >> ([...] on most "64-bit" ports, a real question on amd64 (and others,
> >> if any) which support 32-bit userland.)
> > actually -- our mips64 ports largely use N32 userland, which is 64
> > bit registers and 32 bit addresses.
> 
> Oh!  Thank you.  Yes, that's an interesting case.
> 
> In addition to amd64/i386, it occurs to me that sparc64/sparc32 is
> another case; IIRC it's possible to take sparc64 hardware and build a
> (special? not sure) kernel that runs sparc32 userland.  I've never
> tried it; I don't know whether sparc32 and sparc64 are as freely
> mixable at runtime as amd64 and i386 are under amd64 kernels.

Yes, that's what compat/netbsd32 is for.  (Of course, there are still a 
few things like mount I never bothered to get working across ABIs.)

Eduardo


Re: how to tell if a process is 64-bit

2017-09-08 Thread Mouse
>> ([...] on most "64-bit" ports, a real question on amd64 (and others,
>> if any) which support 32-bit userland.)
> actually -- our mips64 ports largely use N32 userland, which is 64
> bit registers and 32 bit addresses.

Oh!  Thank you.  Yes, that's an interesting case.

In addition to amd64/i386, it occurs to me that sparc64/sparc32 is
another case; IIRC it's possible to take sparc64 hardware and build a
(special? not sure) kernel that runs sparc32 userland.  I've never
tried it; I don't know whether sparc32 and sparc64 are as freely
mixable at runtime as amd64 and i386 are under amd64 kernels.

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Re: how to tell if a process is 64-bit

2017-09-08 Thread Paul.Koning

> On Sep 8, 2017, at 4:00 PM, matthew green  wrote:
> 
>> Is the answer "it's using an ISA with 64-bit registers and addresses"?
>> This actually can be broken down into the "registers" and "addresses"
>> portion, but, in practice, the two tend to go together.  (Always true
>> on most "64-bit" ports, a real question on amd64 (and others, if any)
>> which support 32-bit userland.)
> 
> actually -- our mips64 ports largely use N32 userland, which
> is 64 bit registers and 32 bit addresses.  this is also what
> linux calls "x32" for x86 platforms.  obviously, this does
> require a 64 bit cpu.

That's why I asked "what does 'is 64-bit' mean".  Your previous reference to 
LP64 answers the question "does this program use 64 bit addresses".  There are 
at least two other possible questions: (a) does this program have access to 64 
bit registers, and (b) can this program do operations such as arithmetic on 64 
bit integers.  (a) presumably implies (b) but the two are not equivalent.  For 
example, N32 is (a) and (b) but O32 -- the old "mips32" port -- is (b) but not 
(a).

paul



re: how to tell if a process is 64-bit

2017-09-08 Thread matthew green
> Is the answer "it's using an ISA with 64-bit registers and addresses"?
> This actually can be broken down into the "registers" and "addresses"
> portion, but, in practice, the two tend to go together.  (Always true
> on most "64-bit" ports, a real question on amd64 (and others, if any)
> which support 32-bit userland.)

actually -- our mips64 ports largely use N32 userland, which
is 64 bit registers and 32 bit addresses.  this is also what
linux calls "x32" for x86 platforms.  obviously, this does
require a 64 bit cpu.


.mrg.


re: how to tell if a process is 64-bit

2017-09-08 Thread matthew green
> In a cross-platform process utility tool the question came up how to
> decide if a process is 64-bit.
> 
> https://github.com/giampaolo/psutil/issues/1102
> 
> What's the best answer for NetBSD?

in C:

internally, just check #ifdef _LP64.
externally, kvm_getprocs() with KERN_PROC_PID.

in other languages?  don't ask me.


.mrg.


Re: how to tell if a process is 64-bit

2017-09-08 Thread Martin Husemann
On Fri, Sep 08, 2017 at 01:13:44PM +, Christos Zoulas wrote:
> If you can attach to it with ktrace, the first record is an emul record.
> If you have procfs cat /proc//emul

Yeah, but it would be interesting to see in something like kprocinfo2
(easily fetchable via sysctl or the kvm wrapper).

Martin


Re: how to tell if a process is 64-bit

2017-09-08 Thread Christos Zoulas
In article <20170908115647.ga29...@mail.duskware.de>,
Martin Husemann   wrote:
>On Fri, Sep 08, 2017 at 12:55:37PM +0200, Thomas Klausner wrote:
>> What's the best answer for NetBSD?
>
>If the kernel is 64bit:
>kvm_getproc2() and check the process flags for P_32.
>
>If not: all of them ;-}
>
>I would find it more interesting to answer "what is the emulation it runs
>under", so you have, say: netbsd native x86_64 processes, netbsd_compat32 
>i386 processes, 32 bit linux, 64 bit linux,  (but I don't know an
>easy answer for that).

If you can attach to it with ktrace, the first record is an emul record.
If you have procfs cat /proc//emul

christos



Re: how to tell if a process is 64-bit

2017-09-08 Thread Mouse
>> First, I have to ask: what does it mean to say that a particular
>> process is - or isn't - 64-bit?
> Many 64-bit ports support running 32-bit applications
> (compat_netbsd32, compat_linux32).

Exactly.

Is the answer "it can do arithmetic on 64-bit values"?  (Most - all, I
think - NetBSD ports qualify.  Indeed, I have trouble imagining any
machine with pretensions to general-purpose use, even 8-bitters like
the C=64, that doesn't.)

Is the answer "the CPU has 64-bit internal datapaths"?  (This is not a
per-process thing; it is probably true of some CPUs usually thought of
as 32-bit and probably false of some low-end "64-bit" CPUs.)

Is the answer "it's using an ISA with 64-bit registers and addresses"?
This actually can be broken down into the "registers" and "addresses"
portion, but, in practice, the two tend to go together.  (Always true
on most "64-bit" ports, a real question on amd64 (and others, if any)
which support 32-bit userland.)

Is the answer "it can address more than 4G of VM"?  (This is probably
equivalent, in practice, to the previous one.)

Is the answer "it can address VM above the 4G point"?  (For some ways
of looking at the questions, this is equiavlent to the previous one.  I
think amd64 CPUs can do this under some circumstances when executing
their 32-bit ISA, though I'd have to check the architecture document to
be sure, and they may be limited to something like the 64G point.)

I suspect the original question was thinking of the middle one,
probably with regard to amd64/i386.  I _think_ the CPU in that case can
switch its ISA on the fly; if so, the question may need to be more "is
it a 64-bit process at some particular moment?".  If not, "which
emulation is it using?" may be close enough to be useful, and is easy
to answer, though perhaps somewhat inconvenient (ktrace writes a record
with the emulation type; with no tracing points turned on that should
be all it writes).

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Re: how to tell if a process is 64-bit

2017-09-08 Thread Thomas Klausner
On Fri, Sep 08, 2017 at 07:38:24AM -0400, Mouse wrote:
> First, I have to ask: what does it mean to say that a particular
> process is - or isn't - 64-bit?

Many 64-bit ports support running 32-bit applications
(compat_netbsd32, compat_linux32).
 Thomas


Re: how to tell if a process is 64-bit

2017-09-08 Thread Martin Husemann
On Fri, Sep 08, 2017 at 12:55:37PM +0200, Thomas Klausner wrote:
> What's the best answer for NetBSD?

If the kernel is 64bit:
kvm_getproc2() and check the process flags for P_32.

If not: all of them ;-}

I would find it more interesting to answer "what is the emulation it runs
under", so you have, say: netbsd native x86_64 processes, netbsd_compat32 
i386 processes, 32 bit linux, 64 bit linux,  (but I don't know an
easy answer for that).

Martin


Re: how to tell if a process is 64-bit

2017-09-08 Thread coypu
At the risk of making people angry, this answer works for linux and netbsd:

$ file -L /proc/self/exe
/proc/self/exe: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), 
dynamically linked, interpreter /usr/libexec/ld.elf_so, for NetBSD 8.99.2, not 
stripped



Re: how to tell if a process is 64-bit

2017-09-08 Thread Mouse
> In a cross-platform process utility tool the question came up how to
> decide if a process is 64-bit.

First, I have to ask: what does it mean to say that a particular
process is - or isn't - 64-bit?

I started to write that on most of the 64-bit-supporting ports there
isn't even any question, but then I realized that, depending on the
answer to the above, that may not be true.

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B