Re: CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-17 Thread Rin Okuyama

On 2021/01/18 14:49, Rin Okuyama wrote:

(2) However, in clock.c rev 1.31 and prior, curcpu->ci_idepth was not
     raised before calling {hard,stat}clock(). Therefore, cpu_intr_p()
     wrongly returns false. As a result, callee functions misunderstood
     that they are not running in the interrupt context.


1.31 --> 1.30

Sorry for bothering you many times...

rin


Re: CVS commit: src/sys/arch/powerpc/ibm4xx

2021-01-17 Thread Rin Okuyama

On 2021/01/18 13:35, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Jan 18 04:35:05 UTC 2021

Modified Files:
src/sys/arch/powerpc/ibm4xx: clock.c

Log Message:
Invoke hardclock() and statclock() in the interrupt context.

Otherwise, entropy_enter() is used instead of entropy_enter_intr() in
statclock(), which results in KASSERT() failure.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/arch/powerpc/ibm4xx/clock.c


This message is somewhat misleading. I meant:

(1) Callers are interrupt handlers, therefore, {hard,stat}clock() are
apparently invoked in the interrupt context.

(2) However, in clock.c rev 1.31 and prior, curcpu->ci_idepth was not
raised before calling {hard,stat}clock(). Therefore, cpu_intr_p()
wrongly returns false. As a result, callee functions misunderstood
that they are not running in the interrupt context.

I have to improve my English writing skills ;-).

Thanks,
rin


Re: CVS commit: src/sys/arch/arm/arm32

2020-11-21 Thread Rin Okuyama

Excellent! Thank you so much for finding out and fixing this!

Full ATF successfully completed for Raspberry Pi 2b, which formerly
crashed due to "anon != NULL && anon->an_ref != 0" panic.

Now, ATF is running on Cubietruck and Raspberry Pi Zero W.

Thanks,
rin

On 2020/11/22 4:44, Nick Hudson wrote:

Module Name:src
Committed By:   skrll
Date:   Sat Nov 21 19:44:52 UTC 2020

Modified Files:
src/sys/arch/arm/arm32: cpuswitch.S

Log Message:
Ensure that r5 contains curlwp before DO_AST_AND_RESTORE_ALIGNMENT_FAULTS
in lwp_trampoline as required by the move to make ASTs operate per-LWP
rather than per-CPU.

Thanks to martin@ for bisecting the amap corruption he was seeing and
testing this fix.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/arm/arm32/cpuswitch.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Re: CVS commit: src

2020-11-12 Thread Rin Okuyama

On 2020/11/13 2:35, nia wrote:

I'll revert the commit shortly.


Thank you very much for your quick response.


I wasn't expecting such major breakage (obviously) and actually
did run a build but ran into different problems with libstdc++.


Yeah, this is why we need tests, and also listen to others before
making somewhat big changes. No one is perfect...

Thanks,
rin


Re: CVS commit: src

2020-11-12 Thread Rin Okuyama

On 2020/11/12 23:03, Rin Okuyama wrote:

The backtrace reads:

| (gdb) bt
| #0  0xfc2961bca308 in ?? ()
| #1  0xfc2961b9ec10 in __deregister_frame_info_bases ()
|    from /usr/lib/libgcc_s.so.1
| #2  0xf88425b4 in _rtld_call_function_void (obj=0xfc2962917400,
| addr=277254663434168) at /usr/src/libexec/ld.elf_so/rtld.h:514
| ...

The fault address is anon memory w/o exec permission when su exits:

| # pmap -p xxx
| ...
| FC2961BB1000  4K read/write    /altroot/lib/libgcc_s.so.1.0
| FC2961BB6000 40K read/write  [ anon ]
| FC2961BE6000 40K read/write  [ anon ]
| ...


Oops, correction: the fault address is not mapped when su exits;
FC2961BB6000 + 40K = FC2961BC.

The discussion thereafter does not change.

Thanks,
rin


Re: CVS commit: src

2020-11-12 Thread Rin Okuyama

On 2020/11/11 1:50, nia wrote:

On Tue, Nov 10, 2020 at 04:29:21PM +, Taylor R Campbell wrote:

Module Name:src
Committed By:   nia
Date:   Sun Nov  8 21:56:48 UTC 2020

Modified Files:
 src/external/bsd/kyua-cli: Makefile.inc
 src/external/ibm-public/postfix: Makefile.inc
 src/external/public-domain/sqlite: Makefile.inc
 src/external/public-domain/sqlite/bin: Makefile
 src/external/public-domain/sqlite/lib: Makefile sqlite3.pc.in
 src/usr.sbin/makemandb: Makefile

Log Message:
sqlite: do not build without multithreading support

at least a few pkgsrc packages avoid base sqlite because it fails
this check, and it's probably a surprising performance penalty for
unsuspecting users


Why do we even expose NetBSD's libsqlite3.so to pkgsrc?  Why not just
have pkgsrc always use pkgsrc sqlite3, and change base to go back to
the smaller non-threaded sqlite3 with only the options the things in
base actually need?

Also: What is the performance penalty?  The sqlite3 documentation
(https://www.sqlite.org/faq.html#q6) suggests that _enabling_
SQLITE_THREADSAFE has a performance penalty, not the other way around.

It seems to me we've had a lot of problems over the years trying to
use base sqlite3 for everything in pkgsrc.  It's not clear to me that
any of the recent changes are helpful for the three things in base
that need sqlite3, and it's also not clear that they will help with
running newer pkgsrc on older NetBSD.


libevent is also problematic. Maybe there's just too many third-party
libraries that are exposed that sholdn't be.


A failure for cvs, suspected to be a fallout of threaded sqlite3 was
reported in port-arm@. See thread starts with:

http://mail-index.netbsd.org/port-arm/2020/11/12/msg007046.html

Also, I encountered another fallout: ``su -'' receives SIGSEGV when exits
(on aarch64, but I bet this is MI problem):

| $ su
| # exit
| $ su -
| # exit
| [2]   Segmentation fault (core dumped) su -

The backtrace reads:

| (gdb) bt
| #0  0xfc2961bca308 in ?? ()
| #1  0xfc2961b9ec10 in __deregister_frame_info_bases ()
|from /usr/lib/libgcc_s.so.1
| #2  0xf88425b4 in _rtld_call_function_void (obj=0xfc2962917400,
| addr=277254663434168) at /usr/src/libexec/ld.elf_so/rtld.h:514
| ...

The fault address is anon memory w/o exec permission when su exits:

| # pmap -p xxx
| ...
| FC2961BB1000  4K read/write/altroot/lib/libgcc_s.so.1.0
| FC2961BB6000 40K read/write  [ anon ]
| FC2961BE6000 40K read/write  [ anon ]
| ...

However, when su is running, libpthread is loaded at this address:

| # pmap -p xxx
| ...
| FC2961BB1000  4K read/write/altroot/lib/libgcc_s.so.1.0
| FC2961BB6000 40K read/write  [ anon ]
| FC2961BC 76K read/exec /altroot/lib/libpthread.so.1.4
| FC2961BD3000 64K   /altroot/lib/libpthread.so.1.4
| ...

su is not explicitly linked to libpthread, but it is loaded via libkrb5
via libpam. It registers its own deconstructor, however, it is unloaded
before su exits. Then, SIGSEGV takes place as a result.

IMO, this commit should be reverted ASAP. This kind of change needs more
tests, and discussion in appropriate lists before commit. Unfortunately,
the committer did not even carry out ``build.sh'' before commit (martin
fixed the build failure due to this). This is not what we, at least, I
expect our developers.

Thanks,
rin


Re: CVS commit: src/sys/arch/arm/arm

2020-11-11 Thread Rin Okuyama

On 2020/11/12 6:52, matthew green wrote:

"Rin Okuyama" writes:

Module Name:src
Committed By:   rin
Date:   Tue Nov 10 21:40:07 UTC 2020

Modified Files:
src/sys/arch/arm/arm: cpu_exec.c

Log Message:
Test (epp->ep_esch->es_emul != _netbsd) instead of


nice, this is a step forward.

an optimisation on it could be to remove this test entirely
if neither MODULAR or COMAPT_NETBSD32 are set, as it will
always be false there.


Ah, yes. I will commit after some test. Thanks!

rin


Re: CVS commit: src/share/mk

2020-11-09 Thread Rin Okuyama

On 2020/11/10 1:15, Christos Zoulas wrote:

- when we need to run ctfconvert, go through an intermediate ${.TARGET}.o
   file, instead of writing directly to ${.TARGET} and then overwriting
   ${.TARGET} with ctfconvert. This avoids build failures after a build
   got interrupted (the "partially built from C" scourge).


Thanks, I wanted this!

rin


Re: CVS commit: src/sys

2020-11-07 Thread Rin Okuyama

Thanks Paul for finding out the bug!

Then, compat_netbsd32 and compat_netbsd32_coredump modules are
successfully load for kernel without COMPAT_NETBSD32 option.

However, OABI binaries still do not work. I found this is due to
there remains ``#ifdef COMPAT_NETBSD32'' codes in sys/arch/arm.

By fixing them, OABI binaries work and dump valid core files!

I changed two files.

(1) arm_netbsd_elf32_probe() in arm/cpu_exec.c

Previously, determine whether emulation is native or netbsd32 by
testing ``epp->ep_esch->es_emul == _netbsd32''. This requires
COMPAT_NETBSD32 option. However, we can use
``epp->ep_esch->es_emul != _netbsd'' for this purpose.

(2) arm_netbsd_elf32_coredump_setup() in arm/core_machdep.c

This seems simply a mistake; kernel sets EABI flag to OABI core
files. We can remove entire COMPAT_NETBSD32 codes.

I will commit them soon if there's no objection.

Thanks,
rin

On 2020/11/08 6:53, Paul Goyette wrote:

Thanks for fixing ...

On Sat, 7 Nov 2020, Christos Zoulas wrote:


/usr/obj/evbarm-earmv7/tools/bin/nbmake-evbarm -V MACHINE_ARCH
earmv7


christos


On Nov 7, 2020, at 4:27 PM, Paul Goyette  wrote:

OK, I think I found the problem, but I don't know how to solve it...

All of the undefined symbols are supposed to be provided by

.../sys/arch/arm/arm32/netbsd32_machdep.c

but there is no netbsd32_machdep.o included in the compat_netbsd32
module.  This file should be included by the following code in 
.../sys/modules/compat_netbsd32/Makefile

.if ${MACHINE_ARCH} == "arm"
.PATH:  ${S}/arch/arm/arm32
SRCS+=  netbsd32_machdep.c
.endif

but it seems not to work (or at least, it doesn't do what it was
intended to do).






On Thu, 5 Nov 2020, Rin Okuyama wrote:


On 2020/11/05 5:43, Paul Goyette wrote:

BTW, the patch you submitted with the initial message in this thread
looks good for avoiding the issue.  But I'm not sure it is a complete
solution.
In particular, you would need to build a 32-bit arm that contains ``no
options COMPAT_NETBSD32'' and then boot and load the compat_netbsd32
and compat_netbsd32_coredump modules

    modload compat_netbsd32
    modload compat_netbsd32_coredump
Then see if emulation of the old ABI still works, and check if core-
dump works for old-ADI programs; the test program I've been using for
core-dump checking is

    #include 
    int main(int argc, void *argv) { abort(); }
I really have to leave and take care of some personal business, so I
would greatly appreciate if you can check this out.


Hmm, ``modload compat_netbsd32'' does not work on evbarmv6hf-el:


# uname -ap
NetBSD  9.99.75 NetBSD 9.99.75 (RPI0) #11: Thu Nov  5 20:26:39 JST 2020 
rin@latipes:/sys/arch/evbarm/compile/RPI0 evbarm earmv6hf
# modload compat_netbsd32
[  29.6328410] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_vm_default_addr' not found
[  29.6460400] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_machdep_md_init' not found
[  29.6560750] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_sendsig' not found
[  29.6661200] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_mcontext32_validate' not found
[  29.6791570] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_setmcontext32' not found
[  29.6791570] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_machdep_md_fini' not found
[  29.6948370] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`startlwp32' not found
[  29.7048770] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_getmcontext32' not found
[  29.7168550] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`machine32' not found
[  29.7168550] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_sysarch' not found
[  29.7318320] WARNING: module error: unable to affix module `compat_netbsd32', 
error 8
modload: compat_netbsd32: Exec format error


This should be because there are ``#ifdef COMPAT_NETBSD32'' codes in files
not included in compat_netbsd32 module. compat_netbsd32 module must not
work also for aarch64 and mips64 for the same reason, whereas amd64 and
sparc64 seem OK.

Thanks,
rin

!DSPAM:5fa3f309175521945872603!




++--+---+
| Paul Goyette   | PGP Key fingerprint: | E-mail addresses: |
| (Retired)  | FA29 0E3B 35AF E8AE 6651 | p...@whooppee.com |
| Software Developer | 0786 F758 55DE 53BA 7731 | pgoye...@netbsd.org   |
++--+---+





++--+---+
| Paul Goyette   | PGP Key fingerprint: | E-mail addresses: |
| (Retired)  | FA29 0E3B 35AF E8AE 6651 | p...@whooppee.com |
| Software Developer | 0786 F758 55DE 53BA 7731

Re: CVS commit: src/sys

2020-11-05 Thread Rin Okuyama

On 2020/11/05 23:07, Paul Goyette wrote:

I will investigate.


Thanks!


Can you confirm that it works correctly if you have the built-in
module?  (ie, kernel with ``options COMPAT_NETBSD32'')


Yes, it works fine.

rin


Re: CVS commit: src/sys

2020-11-05 Thread Rin Okuyama

On 2020/11/05 5:43, Paul Goyette wrote:

BTW, the patch you submitted with the initial message in this thread
looks good for avoiding the issue.  But I'm not sure it is a complete
solution.

In particular, you would need to build a 32-bit arm that contains ``no
options COMPAT_NETBSD32'' and then boot and load the compat_netbsd32
and compat_netbsd32_coredump modules

 modload compat_netbsd32
 modload compat_netbsd32_coredump

Then see if emulation of the old ABI still works, and check if core-
dump works for old-ADI programs; the test program I've been using for
core-dump checking is

 #include 
 int main(int argc, void *argv) { abort(); }

I really have to leave and take care of some personal business, so I
would greatly appreciate if you can check this out.


Hmm, ``modload compat_netbsd32'' does not work on evbarmv6hf-el:


# uname -ap
NetBSD  9.99.75 NetBSD 9.99.75 (RPI0) #11: Thu Nov  5 20:26:39 JST 2020  
rin@latipes:/sys/arch/evbarm/compile/RPI0 evbarm earmv6hf
# modload compat_netbsd32
[  29.6328410] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_vm_default_addr' not found
[  29.6460400] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_machdep_md_init' not found
[  29.6560750] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_sendsig' not found
[  29.6661200] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_mcontext32_validate' not found
[  29.6791570] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_setmcontext32' not found
[  29.6791570] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_machdep_md_fini' not found
[  29.6948370] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`startlwp32' not found
[  29.7048770] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`cpu_getmcontext32' not found
[  29.7168550] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`machine32' not found
[  29.7168550] kobj_checksyms, 994: [compat_netbsd32]: linker error: symbol 
`netbsd32_sysarch' not found
[  29.7318320] WARNING: module error: unable to affix module `compat_netbsd32', 
error 8
modload: compat_netbsd32: Exec format error


This should be because there are ``#ifdef COMPAT_NETBSD32'' codes in files
not included in compat_netbsd32 module. compat_netbsd32 module must not
work also for aarch64 and mips64 for the same reason, whereas amd64 and
sparc64 seem OK.

Thanks,
rin


Re: CVS commit: src/sys/kern

2020-11-05 Thread Rin Okuyama

On 2020/11/05 2:45, Paul Goyette wrote:

On Wed, 4 Nov 2020, Rin Okuyama wrote:


On 2020/11/04 22:52, Paul Goyette wrote:

On Wed, 4 Nov 2020, Rin Okuyama wrote:


ptrace_common_{init,fini} are called from the ptrace_common module's
modcmd routine in kern/sys_ptrace_common.c.  The modcmd routine in
turn is called at module initialization time.  In the case of a
built-in module, it will be called by module_init via init_main; if
the module is loaded (or auto-loaded) module_load will call the
modcmd routine.

The module will be built-in if either ``options PTRACE'' or ``file-
system PROCFS'' is set in the kernel configuration file.


Oops, sorry, I meant ptrace_{init,fini}(). These functions are not called
at all since this commit, which forbids ptrace(2) for non-root users.


If the module is built-in (``options PTRACE'' selected in the config
file), then the module will already have been initialized.

If the module is not built-in, then a privileged user will need to
modload(8) the module.

Prior to this change, the built-in ptrace_common module was calling
the ptrace module's init/fini routine.  Quite likely ptrace_common
was built-in (due to inclusion of file-system PROCFS), so the init
was handled during init_main().  This change ensures that the ptrace
init/fini routines are called ONLY if the ptrace module itself (not
the ptrace_common) routine is built-in.

Please check to make sure that ``options PTRACE'' is included in
your kernel config.


Yes:

$ config -x netbsd.gdb | grep PTRACE
###> options    PTRACE  # Include ptrace(2) syscall
###> options    PTRACE_HOOKS    # Include ptrace hooks

The problem is that ptrace_{init,fini}() are not called from
ptrace_modcmd():

https://nxr.netbsd.org/xref/src/sys/kern/sys_ptrace.c#184

   184 static int
   185 ptrace_modcmd(modcmd_t cmd, void *arg)
   186 {
   187 int error;
   188
   189 switch (cmd) {
   190 case MODULE_CMD_INIT:
   191 error = syscall_establish(_netbsd, ptrace_syscalls);
   192 break;
   193 case MODULE_CMD_FINI:
   194 error = syscall_disestablish(_netbsd, ptrace_syscalls);
   195 break;
   196 default:
   197 error = ENOTTY;
   198 break;
   199 }
   200 return error;
   201 }


Yes that would be a problem.


Can you easily confirm that ktrace(2) is unusable for non-privileged
users on 9.99.75 kernel:

$ gdb echo
GNU gdb (GDB) 8.3
...
(gdb) b main
Breakpoint 1 at 0x950: file /usr/src/bin/echo/echo.c, line 58.
(gdb) r
Starting program: /bin/echo
warning: Could not trace the inferior process.
Error:
warning: ptrace: Operation not permitted
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
[1]   Abort trap (core dumped) gdb echo

Also, ptrace_{init,fini} should be moved from sys_ptrace_common.c to
sys_ptrace.c, IMO.


I have some prior obligations, so I won't be able to look at this
until this evening.

Thanks for the detailed analysis.


Fixed. Thanks!

rin


Re: CVS commit: src/sys/kern

2020-11-04 Thread Rin Okuyama

On 2020/11/04 22:52, Paul Goyette wrote:

On Wed, 4 Nov 2020, Rin Okuyama wrote:


ptrace_common_{init,fini} are called from the ptrace_common module's
modcmd routine in kern/sys_ptrace_common.c.  The modcmd routine in
turn is called at module initialization time.  In the case of a
built-in module, it will be called by module_init via init_main; if
the module is loaded (or auto-loaded) module_load will call the
modcmd routine.

The module will be built-in if either ``options PTRACE'' or ``file-
system PROCFS'' is set in the kernel configuration file.


Oops, sorry, I meant ptrace_{init,fini}(). These functions are not called
at all since this commit, which forbids ptrace(2) for non-root users.


If the module is built-in (``options PTRACE'' selected in the config
file), then the module will already have been initialized.

If the module is not built-in, then a privileged user will need to
modload(8) the module.

Prior to this change, the built-in ptrace_common module was calling
the ptrace module's init/fini routine.  Quite likely ptrace_common
was built-in (due to inclusion of file-system PROCFS), so the init
was handled during init_main().  This change ensures that the ptrace
init/fini routines are called ONLY if the ptrace module itself (not
the ptrace_common) routine is built-in.

Please check to make sure that ``options PTRACE'' is included in
your kernel config.


Yes:

$ config -x netbsd.gdb | grep PTRACE
###> optionsPTRACE  # Include ptrace(2) syscall
###> optionsPTRACE_HOOKS# Include ptrace hooks

The problem is that ptrace_{init,fini}() are not called from
ptrace_modcmd():

https://nxr.netbsd.org/xref/src/sys/kern/sys_ptrace.c#184

184 static int
185 ptrace_modcmd(modcmd_t cmd, void *arg)
186 {
187 int error;
188
189 switch (cmd) {
190 case MODULE_CMD_INIT:
191 error = syscall_establish(_netbsd, 
ptrace_syscalls);
192 break;
193 case MODULE_CMD_FINI:
194 error = syscall_disestablish(_netbsd, 
ptrace_syscalls);
195 break;
196 default:
197 error = ENOTTY;
198 break;
199 }
200 return error;
201 }

Can you easily confirm that ktrace(2) is unusable for non-privileged
users on 9.99.75 kernel:

$ gdb echo
GNU gdb (GDB) 8.3
...
(gdb) b main
Breakpoint 1 at 0x950: file /usr/src/bin/echo/echo.c, line 58.
(gdb) r
Starting program: /bin/echo
warning: Could not trace the inferior process.
Error:
warning: ptrace: Operation not permitted
terminate called after throwing an instance of 'gdb_exception_RETURN_MASK_ERROR'
[1]   Abort trap (core dumped) gdb echo

Also, ptrace_{init,fini} should be moved from sys_ptrace_common.c to
sys_ptrace.c, IMO.

Thanks,
rin


Re: CVS commit: src/sys/kern

2020-11-04 Thread Rin Okuyama

On 2020/11/04 22:31, Paul Goyette wrote:

On Wed, 4 Nov 2020, Rin Okuyama wrote:


Hi,

On 2020/10/26 0:55, Paul Goyette wrote:

Module Name:    src
Committed By:    pgoyette
Date:    Sun Oct 25 15:55:37 UTC 2020

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
ptrace_Common is a module unto itself.  Don't use the ptrace module's
init/fini routines.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This commit makes ptrace(2) unusable for non-privileged users;
ptrace_common_{init,fini}() should be called from somewhere.


ptrace_common_{init,fini} are called from the ptrace_common module's
modcmd routine in kern/sys_ptrace_common.c.  The modcmd routine in
turn is called at module initialization time.  In the case of a
built-in module, it will be called by module_init via init_main; if
the module is loaded (or auto-loaded) module_load will call the
modcmd routine.

The module will be built-in if either ``options PTRACE'' or ``file-
system PROCFS'' is set in the kernel configuration file.


Oops, sorry, I meant ptrace_{init,fini}(). These functions are not called
at all since this commit, which forbids ptrace(2) for non-root users.

Thanks,
rin


Re: CVS commit: src/sys

2020-11-03 Thread Rin Okuyama

Hello again,

On 2020/11/02 3:51, Paul Goyette wrote:

Module Name:src
Committed By:   pgoyette
Date:   Sun Nov  1 18:51:03 UTC 2020

Modified Files:
src/sys/compat/netbsd32: netbsd32.h netbsd32_core.c
src/sys/kern: compat_stub.c files.kern kern_core.c kern_sig.c
sys_ptrace_common.c
src/sys/modules: Makefile
src/sys/modules/compat_netbsd32: Makefile
src/sys/modules/coredump: Makefile
src/sys/sys: compat_stub.h param.h signalvar.h
Added Files:
src/sys/modules/compat_netbsd32_coredump: Makefile

Log Message:
Separate the compat_netbsd32_coredump from the compat_netbsd32 and
coredump modules, into its own module.

Welcome to 7.99.75 !!!


To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.15 -r1.16 src/sys/compat/netbsd32/netbsd32_core.c
cvs rdiff -u -r1.20 -r1.21 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/files.kern
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/kern_core.c
cvs rdiff -u -r1.394 -r1.395 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.88 -r1.89 src/sys/kern/sys_ptrace_common.c
cvs rdiff -u -r1.247 -r1.248 src/sys/modules/Makefile
cvs rdiff -u -r1.35 -r1.36 src/sys/modules/compat_netbsd32/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/compat_netbsd32_coredump/Makefile
cvs rdiff -u -r1.7 -r1.8 src/sys/modules/coredump/Makefile
cvs rdiff -u -r1.24 -r1.25 src/sys/sys/compat_stub.h
cvs rdiff -u -r1.677 -r1.678 src/sys/sys/param.h
cvs rdiff -u -r1.102 -r1.103 src/sys/sys/signalvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This commit breaks arm, i.e., ILP32 arch with COMPAT_NETBSD32. For arm,
coredump_elf32_hook is already hooked in the main kernel. Therefore,
compat_netbsd32_coredump_modcmd(MODULE_CMD_INIT) causes KASSERT failure:

panic: kernel diagnostic assertion "!*hooked" failed: file 
"../../../../kern/kern_module_hook.c", line 70

Does the attached patch seem reasonable to you?

Thanks,
rin
Index: sys/compat/netbsd32/netbsd32_core.c
===
RCS file: /home/netbsd/src/sys/compat/netbsd32/netbsd32_core.c,v
retrieving revision 1.16
diff -p -u -r1.16 netbsd32_core.c
--- sys/compat/netbsd32/netbsd32_core.c 1 Nov 2020 18:51:02 -   1.16
+++ sys/compat/netbsd32/netbsd32_core.c 4 Nov 2020 06:52:52 -
@@ -68,11 +68,15 @@ compat_netbsd32_coredump_modcmd(modcmd_t
switch (cmd) {
case MODULE_CMD_INIT:
MODULE_HOOK_SET(coredump_netbsd32_hook, real_coredump_netbsd32);
+#ifdef _LP64
MODULE_HOOK_SET(coredump_elf32_hook, real_coredump_elf32);
+#endif
return 0;
case MODULE_CMD_FINI:
MODULE_HOOK_UNSET(coredump_netbsd32_hook);
+#ifdef _LP64
MODULE_HOOK_UNSET(coredump_elf32_hook);
+#endif
return 0;
default:
return ENOTTY;


Re: CVS commit: src/sys/kern

2020-11-03 Thread Rin Okuyama

Hi,

On 2020/10/26 0:55, Paul Goyette wrote:

Module Name:src
Committed By:   pgoyette
Date:   Sun Oct 25 15:55:37 UTC 2020

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
ptrace_Common is a module unto itself.  Don't use the ptrace module's
init/fini routines.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This commit makes ptrace(2) unusable for non-privileged users;
ptrace_common_{init,fini}() should be called from somewhere.

Thanks,
rin


Re: CVS commit: src/sys/dev/wsfb

2020-10-21 Thread Rin Okuyama

Hi,

On 2020/10/21 15:42, Michael wrote:

Hello,

On Sun, 18 Oct 2020 11:54:21 +
"Rin Okuyama"  wrote:


Module Name:src
Committed By:   rin
Date:   Sun Oct 18 11:54:21 UTC 2020

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
For WSDISPLAYIO_GET_FBINFO ioctl, set WSFB_VRAM_IS_RAM to fbi_flags
when shadow FB is used.


This flag is a hint for X, telling it that the memory used as
framebuffer is regular RAM ( where using a shadowfb in X would be a
waste of time and RAM ), not for example PCI RAM ( where a shadowfb
would be faster ).
In other words, it's supposed to tell X not to shadow the framebuffer.
This is why it's not set by genfb itself, which doesn't have such
knowledge about the hardware, but by drivers which do.
Shadow fb use in wsdisplay is completely private and mapping the
framebuffer through genfb will always give you whatever genfb thinks is
the actual device framebuffer.


Thank you for detailed explanation!

I already reverted this commit as jmcneill@ advised me:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/wsfb/genfb.c#rev1.77

Thanks,
rin


Re: CVS commit: src/external/gpl3/gcc/dist/gcc/config/aarch64

2020-10-20 Thread Rin Okuyama

Hi,
(tech-toolchain@ added to cc)

On 2020/10/16 1:49, Kamil Rytarowski wrote:

On 15.10.2020 17:14, Rin Okuyama wrote:

On 2020/10/15 16:12, matthew green wrote:

Martin Husemann writes:

On Thu, Oct 15, 2020 at 05:28:12PM +1100, matthew green wrote:

you could try reverting most of our changes to this file and
making sure you run with /proc mounted -o linux.  ryo@ recently
added additional /proc/cpuinfo support that should make this
just work with the upstream version, but i haven't had chance
to update and see if this is the case.


I've confirmed that -mtune=native works fine at least for A53,
even if all the local changes to driver-aarch64.c is reverted.
I will commit it soon.


If we go this route, we should make the relevant procfs nodes
independent
of -o linux.


that would be fine by me.


Nowadays, -o linux is turned on by default (unless nolinux is
specified explicitly). Still, native apps probably should not
depend on it.

This needs MI changes to procfs, not MD to aarch64. Should we
enable /proc/cpuinfo unconditionally?



I'm against the policy of restoring the /proc dependency for this corner
case in one application.

We need to upstream the NetBSD specific patches to mainline GCC.


I'm also one who feels hesitate to import Linux'ism into our basic
components. However, for this problem in particular, I still think
it is not a good choice to keep NetBSD support in driver-aarch64.c:

(a) Our sysctl(3)-based interface is not compliant to any standards,
just like Linux's /proc/cpuinfo. But the latter is, unfortunately
for us, the de facto standard.

(b) Because of (a), driver-aarch64.c is deeply depended on
/proc/cpuinfo. Our NetBSD support code

see diff to vendor branch here:
http://cvsweb.netbsd.org/bsdweb.cgi/src/external/gpl3/gcc/dist/gcc/config/aarch64/driver-aarch64.c.diff?r1=1.1.1.7=1.10=h

is something like a "glue code" which converts our convention to
/proc/cpuinfo style. We already do this in procfs. Why twice?

(c) I imagine that there would be little benefits for upstream to
merge NetBSD support into their repository. If they will merge,
I don't think the code is kept updated.

(d) Only -march=native and -mtune=native depends on this feature. I'm
OK with /proc/cpuinfo is left as is; only enabled when -onolinux is
not specified. IMO, it is users' responsibility that such a
additional feature fails with their non-standard system settings.

In short, I'm worried about future when mrg@ or someone else have to
maintain our glue code eternally, if this code is not reverted.

Thanks,
rin


Re: CVS commit: src/sys

2020-10-20 Thread Rin Okuyama

Hi,

This causes build failures for LP64 archs without COMPAT_NETBSD32,
i.e., alpha and ie64:

kern_core.o: in function `coredump_modcmd':
(.text+0x1c4): undefined reference to `real_coredump_elf32

https://releng.netbsd.org/builds/HEAD/202010200300Z/

(Failure for aarch64eb is irrelevant, and already fixed by ryo.)

Protect the code with COMPAT_NETBSD32 or EXEC_ELF32?

Thanks,
rin

On 2020/10/20 4:33, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Mon Oct 19 19:33:02 UTC 2020

Modified Files:
src/sys/arch/amd64/conf: MODULAR files.amd64
src/sys/kern: compat_stub.c core_elf32.c files.kern kern_core.c
kern_sig.c
src/sys/modules/coredump: Makefile
src/sys/modules/exec_elf32: Makefile
src/sys/modules/exec_elf64: Makefile
src/sys/modules/ptrace_common: Makefile
src/sys/sys: compat_stub.h exec_elf.h
Added Files:
src/sys/modules/ptrace_common: machdep.mk

Log Message:
Arrange so that no options COREDUMP and no options PTRACE work together.
Thanks to Paul Goyette for testing.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/conf/MODULAR
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/amd64/conf/files.amd64
cvs rdiff -u -r1.19 -r1.20 src/sys/kern/compat_stub.c
cvs rdiff -u -r1.65 -r1.66 src/sys/kern/core_elf32.c
cvs rdiff -u -r1.52 -r1.53 src/sys/kern/files.kern
cvs rdiff -u -r1.30 -r1.31 src/sys/kern/kern_core.c
cvs rdiff -u -r1.390 -r1.391 src/sys/kern/kern_sig.c
cvs rdiff -u -r1.6 -r1.7 src/sys/modules/coredump/Makefile
cvs rdiff -u -r1.5 -r1.6 src/sys/modules/exec_elf32/Makefile
cvs rdiff -u -r1.4 -r1.5 src/sys/modules/exec_elf64/Makefile
cvs rdiff -u -r1.3 -r1.4 src/sys/modules/ptrace_common/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/ptrace_common/machdep.mk
cvs rdiff -u -r1.23 -r1.24 src/sys/sys/compat_stub.h
cvs rdiff -u -r1.167 -r1.168 src/sys/sys/exec_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Re: CVS commit: src/sys/dev/wsfb

2020-10-18 Thread Rin Okuyama

On 2020/10/18 21:18, Jared McNeill wrote:

I think WSFB_VRAM_IS_RAM is meant to be a hint for what kind of memory you get 
when you mmap the device. When shadow FB is used, that is generally only used 
for rasops and mmap bypasses the shadow and uses device memory directly. So I 
think this could cause performance regressions on such hardware where shadow FB 
is enabled and reading VRAM is slow.

What problem are you attempting to solve with this change?


Ah, I misunderstood its intention. I will revert this commit.
Thank you for pointing out!

PS
I came across this flag bit when I was examining byte-order problems
of framebuffer on aarch64eb. I'm just going to send a message to you.
I will soon!

Thanks,
rin


Re: CVS commit: src/external/gpl3/gcc/dist/gcc/config/aarch64

2020-10-15 Thread Rin Okuyama

On 2020/10/15 16:12, matthew green wrote:

Martin Husemann writes:

On Thu, Oct 15, 2020 at 05:28:12PM +1100, matthew green wrote:

you could try reverting most of our changes to this file and
making sure you run with /proc mounted -o linux.  ryo@ recently
added additional /proc/cpuinfo support that should make this
just work with the upstream version, but i haven't had chance
to update and see if this is the case.


I've confirmed that -mtune=native works fine at least for A53,
even if all the local changes to driver-aarch64.c is reverted.
I will commit it soon.


If we go this route, we should make the relevant procfs nodes independent
of -o linux.


that would be fine by me.


Nowadays, -o linux is turned on by default (unless nolinux is
specified explicitly). Still, native apps probably should not
depend on it.

This needs MI changes to procfs, not MD to aarch64. Should we
enable /proc/cpuinfo unconditionally?


i had to write the netbsd version of that code twice so far.
once for gcc 8.3 and 8.4, once for gcc 8.5 and 9.3, and i'd
really rather avoid having to write another version :)


Oh... Thank you very much for your hard works!

Thanks,
rin


Re: CVS commit: src/sys/arch/aarch64/aarch64

2020-10-13 Thread Rin Okuyama

On 2020/10/13 19:57, Kamil Rytarowski wrote:

On 13.10.2020 09:04, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Tue Oct 13 07:04:49 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c

Log Message:
BE32 binaries are no longer supported for ARMv7 and later, and
therefore for aarch64eb.

Reject them with ENOEXEC, rather than causing illegal instruction
exceptions due to unexpected binary format.




Not supported in general or on NetBSD? Big Endian 32bit is supported on
Cavium ThunderX (at least on a selection of models if not all of them).



BE32 does not mean "big endian 32bit binary". It is an old binary format for
big endian 32-bit executables, that is supported up to ARMv6. ARMv7 and later
only support a new binary format, BE8.

BE8 binaries work without problem with COMPAT_NETBSD32 on aarch64eb.

Thanks,
rin


Re: CVS commit: src/sys/arch/aarch64/aarch64

2020-10-06 Thread Rin Okuyama

It works fine now. Thank you for quick fix!!

rin

On 2020/10/06 15:28, Nick Hudson wrote:


On 06/10/2020 01:54, Rin Okuyama wrote:

Hi,

On 2020/10/01 1:35, Nick Hudson wrote:

Module Name:    src
Committed By:    skrll
Date:    Wed Sep 30 16:35:49 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S vectors.S

Log Message:
Move el[01]_trap_exit into vectors.S where the callers exist


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/aarch64/aarch64/vectors.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This commit seems to break COMPAT_NETBSD32. On RPI3, earmv7hf binaries
get SIGSEGV:


Hopefully fixed now with the commit below. Please let me know if you
have any other problems.

Sorry for the breakage.

Nick


Module Name:    src
Committed By:    skrll
Date:    Tue Oct  6 06:26:46 UTC 2020

Modified Files:
 src/sys/arch/aarch64/aarch64: cpuswitch.S vectors.S

Log Message:
move #include "opt_compat_netbsd32.h" to where it's required


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/aarch64/aarch64/vectors.S




Re: CVS commit: src/sys/arch/aarch64/aarch64

2020-10-05 Thread Rin Okuyama

Hi,

On 2020/10/01 1:35, Nick Hudson wrote:

Module Name:src
Committed By:   skrll
Date:   Wed Sep 30 16:35:49 UTC 2020

Modified Files:
src/sys/arch/aarch64/aarch64: cpuswitch.S vectors.S

Log Message:
Move el[01]_trap_exit into vectors.S where the callers exist


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/arch/aarch64/aarch64/cpuswitch.S
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/aarch64/aarch64/vectors.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This commit seems to break COMPAT_NETBSD32. On RPI3, earmv7hf binaries
get SIGSEGV:

---
# uname -a
NetBSD  9.99.73 NetBSD 9.99.73 (GENERIC64) #33: Mon Oct  5 23:26:29 JST 2020  
rin@latipes:/sys/arch/evbarm/compile/GENERIC64 evbarm
# file /emul/netbsd32/bin/sh
/emul/netbsd32/bin/sh: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 
(SYSV), dynamically linked, interpreter /libexec/ld.elf_so, for NetBSD 9.99.73, 
compiled for: earmv7hf, not stripped
# /emul/netbsd32/bin/sh
[1]   Segmentation fault (core dumped) /emul/netbsd32/bin/sh
# ktrace /emul/netbsd32/bin/sh
[1]   Segmentation fault (core dumped) ktrace /emul/netbsd32/bin/sh
# kdump | tail
   171171 sh   CALL  netbsd32_break(0xb74ffdc)
   171171 sh   RET   netbsd32_break 0
   171171 sh   CALL  netbsd32___clock_gettime50(3,0xfff997f8)
   171171 sh   RET   netbsd32___clock_gettime50 0
   171171 sh   CALL  netbsd32___clock_gettime50(3,0xfff997f8)
   171171 sh   RET   netbsd32___clock_gettime50 0
   171171 sh   CALL  netbsd32___clock_gettime50(3,0xfff99810)
   171171 sh   RET   netbsd32___clock_gettime50 0
   171171 sh   PSIG  SIGSEGV SIG_DFL: code=SEGV_MAPERR, addr=0x8, 
trap=-1845493754)
   171171 sh   NAMI  "sh.core"
---

Full kdump is provided here:

http://www.netbsd.org/~rin/aarch64_netbsd32_kdump_20201006.txt

By reverting this commit, arm32 binaries become working again.
Can you take a look please?

Thanks,
rin


Re: CVS commit: src/crypto/external/bsd/openssl

2020-10-05 Thread Rin Okuyama

Hi,

On 2020/10/05 4:32, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Sun Oct  4 19:32:48 UTC 2020

Modified Files:
src/crypto/external/bsd/openssl/dist/crypto/bn: bn_print.c
src/crypto/external/bsd/openssl/dist/include/openssl: bn.h
src/crypto/external/bsd/openssl/lib/libcrypto: crypto.map

Log Message:
Add BN_oct2bn(3) for factor(6)


To generate a diff of this commit:
cvs rdiff -u -r1.1.1.10 -r1.2 \
 src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c
cvs rdiff -u -r1.1.1.3 -r1.2 \
 src/crypto/external/bsd/openssl/dist/include/openssl/bn.h
cvs rdiff -u -r1.8 -r1.9 \
 src/crypto/external/bsd/openssl/lib/libcrypto/crypto.map


This commit breaks tests/crypto/libcrypto/t_libcrypto:bn as

| # atf-run t_libcrypto
| ...
| tc-se:stderr:
| tc-se:# ERROR: (bool) 'BN_asc2bn(, "0") == true' failed @ 
/usr/src/crypto/external/bsd/openssl/dist/test/bntest.c:1865
| tc-se:# false
| tc-se:# ERROR: (bool) 'BN_asc2bn(, test->base10) == true' failed @ 
/usr/src/crypto/external/bsd/openssl/dist/test/bntest.c:1930
| tc-se:# false
| tc-se:
| tc-end: 1601892266.153458, bn, failed, atf-check failed; see the output of 
the test for details


Index: src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c
diff -u src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.1.1.10 
src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.2
--- src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c:1.1.1.10  Sat Mar 
21 20:49:05 2020
+++ src/crypto/external/bsd/openssl/dist/crypto/bn/bn_print.c   Sun Oct  4 
15:32:48 2020

...

@@ -273,9 +354,14 @@ int BN_asc2bn(BIGNUM **bn, const char *a
  if (*p == '-')
  p++;
  
-if (p[0] == '0' && (p[1] == 'X' || p[1] == 'x')) {

-if (!BN_hex2bn(bn, p + 2))
-return 0;
+if (p[0] == '0') {
+   if (p[1] == 'X' || p[1] == 'x') {
+   if (!BN_hex2bn(bn, p + 2))
+   return 0;
+   } else {
+   if (!BN_oct2bn(bn, p + 1))
+   return 0;
+   }
  } else {
  if (!BN_dec2bn(bn, p))
  return 0;



This part probably should be

| } else if (p[1] != '\0') {
|   if (!BN_oct2bn(bn, p + 1))
|   return 0;
| }

Otherwise, conversion fails for "0".

Thanks,
rin


Re: CVS commit: src/sys/dev/fdt

2020-10-02 Thread Rin Okuyama

On 2020/10/02 22:42, Jonathan A. Kollasch wrote:

On Sun, Jul 21, 2019 at 03:57:24PM +, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Sun Jul 21 15:57:24 UTC 2019

Modified Files:
src/sys/dev/fdt: dw_apb_uart.c

Log Message:
The device cannot recognize break signal. Use + (five plus signs) as
cnmagic in the same manner with bcm2835_com.c.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/fdt/dw_apb_uart.c



This does not appear to be needed on at least one SoC (Allwinner H5).
Which SoC did you have this problem on?


Oops, you are right.

It seems that my device (Allwinner A20) did not accept break signal
because of WSDISPLAY_MULTICONS option. At that time, kernel just
ignored break signal, but today it panics instead. Anyway, by
disabling wsdisplay, I can enter DDB from console by break signal.

I will revert this commit, and request pullup to netbsd-9.

Thank you for finding it out, and I'm sorry for bothering you.

rin


Re: CVS commit: src/external/gpl3/gcc

2020-09-10 Thread Rin Okuyama

Hi again,

On 2020/09/10 21:53, Kamil Rytarowski wrote:

Module Name:src
Committed By:   kamil
Date:   Thu Sep 10 12:53:06 UTC 2020

Modified Files:
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common:
sanitizer_linux_libcdep.cc
src/external/gpl3/gcc/lib: Makefile.sanitizer

Log Message:
Avoid using internal RTLD/libpthread/libc symbol in sanitizers


...

Index: 
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
diff -u 
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc:1.15
 
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc:1.16
--- 
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc:1.15
Mon Sep  7 07:10:43 2020
+++ 
src/external/gpl3/gcc/dist/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
 Thu Sep 10 12:53:05 2020
@@ -47,6 +47,7 @@
  #if SANITIZER_NETBSD
  #include 
  #include 
+#include 
  #endif
  
  #if SANITIZER_SOLARIS

@@ -417,13 +418,7 @@ uptr ThreadSelf() {
  
  #if SANITIZER_NETBSD

  static struct tls_tcb * ThreadSelfTlsTcb() {
-  struct tls_tcb * tcb = NULL;
-# ifdef __HAVE___LWP_GETTCB_FAST
-  tcb = (struct tls_tcb *)__lwp_gettcb_fast();
-# elif defined(__HAVE___LWP_GETPRIVATE_FAST)
-  tcb = (struct tls_tcb *)__lwp_getprivate_fast();
-# endif
-  return tcb;
+  return (struct tls_tcb *)_lwp_getprivate();
  }
  
  uptr ThreadSelf() {




This change breaks at least mips and powerpc, in which the return value of
__lwp_getprivate(2), i.e., curlwp->l_private is not tcb address itself, but
biased one. On the other hand, the return value of __lwp_gettcb_fast() is
unbiased address; see sys/arch/{mips,powerpc}/include/mcontext.h.

For powerpc, I recently attempted to change l_private to store tcb address
itself:

http://www.nerv.org/netbsd/?q=id:20200621T004000Z.95c1a18070b53713ce2c763df7f40743bf74172c

But I reverted it soon as requested by joerg:

http://www.nerv.org/netbsd/?q=id:20200622T053457Z.05db3be87b5ad499f5d1adba755bc573fd241c87

His reasoning was that kernel must not know the ABI details in userland.
I fully agree with this. See above links for more details.

Thanks,
rin


Re: CVS commit: src

2020-09-10 Thread Rin Okuyama

On 2020/09/10 18:28, Kamil Rytarowski wrote:

On 10.09.2020 10:50, Rin Okuyama wrote:

On 2020/09/10 16:41, Kamil Rytarowski wrote:

On 10.09.2020 03:53, Rin Okuyama wrote:

Module Name:src
Committed By:rin
Date:Thu Sep 10 01:53:22 UTC 2020

Modified Files:
 src/distrib/sets/lists/base: mi
 src/distrib/sets/lists/comp: mi
 src/sys/dev: Makefile

Log Message:
Unconditionally install kernel headers for iSCSI as required by
sanitizer shipped with GCC9.

Fix build release with HAVE_GCC=9 for sun2, where MKISCSI=no by default.



Please redo this commit with __has_include(), example:

https://github.com/llvm/llvm-project/commit/7f6b25ad1bb3f8057655a9bad2a3b69621f4a543#diff-fa188a123646bb8c30d7fa22d61ef680




Hmm, I'm not sure whether it is worth the maintenance cost and
complexities it adds... Is there any reason why we should not
install these headers?



The headers are optional and sanitizers shall not dictate what headers
are installed.

Meanwhile, I'm going to do this in upstream LLVM.


Yes, I really appreciate your continuous efforts in syncing our
codes with upstream.

However, still, there is ``the maintenance cost'' in our local
repository. With __has_include(), we must maintain two copies of
headers in the tree. This is dangerous potentially.

My question was whether it is worth the risk not to install few
number of small headers.

Thanks,
rin


Re: CVS commit: src

2020-09-10 Thread Rin Okuyama

On 2020/09/10 16:41, Kamil Rytarowski wrote:

On 10.09.2020 03:53, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Thu Sep 10 01:53:22 UTC 2020

Modified Files:
src/distrib/sets/lists/base: mi
src/distrib/sets/lists/comp: mi
src/sys/dev: Makefile

Log Message:
Unconditionally install kernel headers for iSCSI as required by
sanitizer shipped with GCC9.

Fix build release with HAVE_GCC=9 for sun2, where MKISCSI=no by default.



Please redo this commit with __has_include(), example:

https://github.com/llvm/llvm-project/commit/7f6b25ad1bb3f8057655a9bad2a3b69621f4a543#diff-fa188a123646bb8c30d7fa22d61ef680



Hmm, I'm not sure whether it is worth the maintenance cost and
complexities it adds... Is there any reason why we should not
install these headers?

Thanks,
rin


Re: CVS commit: src/sys/arch

2020-08-16 Thread Rin Okuyama

On 2020/08/11 10:24, matthew green wrote:

XXX
Apply similar fixes to other m68k ports.


yes...but also, a long-term project to consolidate all the
almost-identical m68k code copied into each port would
avoid this probably :-)


Agreed. Also, I've found many dead codes in amiga/locore.s.
I'd like to clean them up little by little.

Thanks,
rin


Re: CVS commit: src/external/gpl3/gcc/dist/gcc/config/m68k

2020-08-16 Thread Rin Okuyama

Sorry for the late reply.

On 2020/08/11 1:16, Valery Ushakov wrote:

This sounds eerily similar to port-macppc/54827 - there's quite a bit
of confusion early on on my part there, but scroll to the last couple
of mails.  http://gnats.netbsd.org/54827

It looks like some logic changed in MI gcc8 that broke netbsd MD
config headers and I wonder if you see the same problem here.  For
macppc the fix was also to undo the netbsd change to STACK_BOUNDARY in
favor of PREFERRED_STACK_BOUNDARY.


Thank you for remaining me that PR. I was following discussion at
that time, but I'd forgotten that it was due to STACK_BOUNDARY.

On 2020/08/11 10:27, matthew green wrote:

May be we should also check other ports for similar gotcha proactively?


good idea.  no other gcc/config/*/*netbsd* files define the
nasty STACK_BOUNDARY macro so hopefully we're good now.


Yes, powerpc and m68k were the last ones.

We somehow gained a bit more experience to overcome troubles
caused by GCC. I think that we can deal with similar problems
better in the next time :).

Thanks,
rin


Re: CVS commit: src/sys/arch/amiga/amiga

2020-08-08 Thread Rin Okuyama

Hi,

Sorry for the serious delay in my response.

On 2020/07/22 13:37, matthew green wrote:

thanks for getting more m68k working!


Thanks!


"Rin Okuyama" writes:

Module Name:src
Committed By:   rin
Date:   Tue Jul 21 06:39:31 UTC 2020

Modified Files:
src/sys/arch/amiga/amiga: locore.s

Log Message:
Align tmpstk to 4-byte boundary in the same manner as mac68k.

However, unfortunately, this does not fix strange crashes of GCC8-compiled
kernel, for which I cannot even enter DDB nor obtain crash dump.

We need further investigation...


boo.  can you update the README.gcc8 file (external/gpl3/gcc),
for the m68k: line on L87 or so, and add 'y' for the known
working kernels, and 'n' for the failed ones.


Finally, I managed GCC8 to work for amiga kernel! Can you please take a
look into port-m68k/6 ?

http://gnats.netbsd.org/6

I will update the table when the patch in the PR and related ones are
committed. After that, I think m68k ports can be switched to GCC8.

Thanks,
rin


Re: CVS commit: src/sys/uvm

2020-07-18 Thread Rin Okuyama

On 2020/07/18 17:30, Jukka Ruohonen wrote:

On Sat, Jul 18, 2020 at 05:19:07PM +0900, Rin Okuyama wrote:

For most (all?) ports, these specifiers are exposed only for
_KERNEL and friends. So, inttypes(*3*) would not be the best
place for them. Currently, I'm not sure where they should be.
/usr/share/misc/style?


Perhaps a new inttypes(9)?  Another option would be a split akin to
types(3).


I prefer to types(3); there already be types only for _KERNEL
namespace. But no strong opinion from me.

Thanks,
rin


Re: CVS commit: src/sys/uvm

2020-07-18 Thread Rin Okuyama

On 2020/07/16 16:02, matthew green wrote:

thanks!  i'll try to remember we have PRIxPADDR because i
considered looking for it and thought we didn't have it...


My pleasure!

On 2020/07/16 16:10, Jukka Ruohonen wrote:

The whole { PRIxPADDR, PRIxPSIZE, ..., PRIxREGISTER } family
should probably be documented in inttypes(3)?


For most (all?) ports, these specifiers are exposed only for
_KERNEL and friends. So, inttypes(*3*) would not be the best
place for them. Currently, I'm not sure where they should be.
/usr/share/misc/style?

Thanks,
rin


Re: CVS commit: src/sys/arch/powerpc/booke

2020-07-06 Thread Rin Okuyama

On 2020/07/07 9:51, Jason Thorpe wrote:

On Jul 6, 2020, at 5:28 PM, Rin Okuyama  wrote:

Module Name:src
Committed By:   rin
Date:   Tue Jul  7 00:28:31 UTC 2020

Modified Files:
src/sys/arch/powerpc/booke: e500_tlb.c

Log Message:
Fix kernel panic due to tmpfs.

pmap for booke assumes that the ``va'' argument for pmap_kenter_pa(9) is
page-aligned. However, by recent changes, tmpfs became to use ``va'' with
page offset via ubc_uiomove(9). So, truncate it to page boundary.


This change seems wrong.  I think it needs to be fixed in tmpfs.


Thank you for your comment. OK, I will revert this and send PR.

rin


Re: CVS commit: src/sys/arch/powerpc/include

2020-06-27 Thread Rin Okuyama

Perhaps yes, but I'm not sure. How do you mips guys think?

Thanks,
rin

On 2020/06/27 19:08, Jaromír Doleček wrote:

Perhaps we can use a similar technique for mips too? There also the
kernel actually always uses a compile-time fixed page size AFAICS.

Jaromir

Le sam. 27 juin 2020 à 04:51, Rin Okuyama  a écrit :


Module Name:src
Committed By:   rin
Date:   Sat Jun 27 02:51:23 UTC 2020

Modified Files:
 src/sys/arch/powerpc/include: vmparam.h

Log Message:
Restrict {MIN,MAX}_PAGE_SIZE for MODULAR || _MODULE, which makes
non-MODULAR kernel a little bit efficient.

They are also exposed to userland for jemalloc.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/powerpc/include/vmparam.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Re: CVS commit: src/sys/arch/mips/cavium/dev

2020-06-26 Thread Rin Okuyama

Hi,

On 2020/06/23 14:18, Simon Burge wrote:

Module Name:src
Committed By:   simonb
Date:   Tue Jun 23 05:18:43 UTC 2020

Modified Files:
src/sys/arch/mips/cavium/dev: octeon_uart.c

Log Message:
Add support for a very simple output-only console so early printf() can work.
Minor tweaks, remove some unused code.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/mips/cavium/dev/octeon_uart.c


Didn't you forget to ``cvs add octeon_uartvar.h''? Periodic build fails as:

|/home/source/ab/HEAD/src/sys/arch/mips/cavium/dev/octeon_uart.c:48:10: fatal 
error: mips/cavium/dev/octeon_uartvar.h: No such file or directory
| #include 
|  ^~

Thanks,
rin


Re: CVS commit: src/external/cddl/dtracetoolkit/dist/Man/man1m

2020-06-25 Thread Rin Okuyama

On 2020/06/25 17:39, Sevan Janiyan wrote:

On 25/06/2020 08:48, Rin Okuyama wrote:
 > Thank you for working on this, but this makes sync with upstream
 > very difficult...

I will be upstreaming these changes. upstream: github.com/opendtrace/toolkit
Just need to find a better way for presenting the columns for field 
descriptions, before I raise the pull request.


Thank you!


 > The best way should be automatically converting them by some script
 > when building. But if it is too difficult, we can install these files
 > as is with minimum adjustments for our system; mandoc still works for
 > them, although output is not very beautiful.

I shouldn't have made the changes here for another reason, as the manuals are 
in man1m/$name.1m, it doesn't fit in easily with the mechanism we have in 
src/share/mk for installing manuals which assumes $name.[1-9].


Hmm, no idea at the moment...

Thanks,
rin


Re: CVS commit: src/external/cddl/dtracetoolkit/dist/Man/man1m

2020-06-25 Thread Rin Okuyama

Hi,

On 2020/06/25 3:06, Sevan Janiyan wrote:

Module Name:src
Committed By:   sevan
Date:   Wed Jun 24 18:06:01 UTC 2020

Modified Files:
src/external/cddl/dtracetoolkit/dist/Man/man1m: opensnoop.1m

Log Message:
mdocify


Thank you for working on this, but this makes sync with upstream
very difficult...

The best way should be automatically converting them by some script
when building. But if it is too difficult, we can install these files
as is with minimum adjustments for our system; mandoc still works for
them, although output is not very beautiful.

Thanks,
rin


Re: CVS commit: src/distrib/sets/lists/man

2020-06-23 Thread Rin Okuyama

On 2020/06/24 6:34, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Tue Jun 23 21:34:44 UTC 2020

Modified Files:
src/distrib/sets/lists/man: mi

Log Message:
Fix prefix for previous.


Oops, s/prefix/suffix/ apparently. I need coffee...

Thanks,
rin


Re: CVS commit: src/tests/lib/libc/sys

2020-06-22 Thread Rin Okuyama

Committed. Thank you for your comment!

rin

On 2020/06/22 20:09, Kamil Rytarowski wrote:

On 22.06.2020 04:51, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Jun 22 02:51:07 UTC 2020

Modified Files:
src/tests/lib/libc/sys: t_ptrace_signal_wait.h t_ptrace_wait.h

Log Message:
Turn trigger_fpe() back to integer division by zero for a while
until QEMU bug #1668041 is fixed:

https://bugs.launchpad.net/qemu/+bug/1668041

by which floating-point division by zero is not trapped correctly
both on amd64 and i386.

Skip *_crash_fpe tests on powerpc, where integer division by zero
is never trapped.




The intention of this test is just detecting SIGFPE. If the si_code
value is various on different architectures (like one traps on integers
other one on floats), we shall just drop the asserts for si_code and
adapt the trigger_fpe() function to cover promptly more ports.

The qemu bug should be fixed nonetheless.




Re: CVS commit: src/sys/arch/powerpc

2020-06-21 Thread Rin Okuyama

On 2020/06/22 5:10, Joerg Sonnenberger wrote:

On Sun, Jun 21, 2020 at 12:40:00AM +, Rin Okuyama wrote:

- Obsolete __lwp_settcb() in order to let kernel know new TLS address via
   _lwp_setprivate(2). Alternatively, we can call _lwp_setprivate(2) within
   __lwp_settcb() like mips, but it is just double handling; we adjust %r2
   appropriately in _lwp_setprivate(2) via cpu_lwp_setprivate().


If an architecture stores the TCB at an offset, it should provide
__lwp_settcb to do the necessary adjust and then invoke _lwp_setprivate
as appropiate. The MIPS variant is correct. This should *not* be done in
the kernel, as it is an ABI detail of the userland TLS API.


Thank you for your comment. I agree. Tt is cleaner not to bring in
userland ABI details into kernel. OK, I will fix it differently.

Thanks,
rin


Re: CVS commit: src/tests/lib/libc/sys

2020-06-17 Thread Rin Okuyama

On 2020/06/17 17:42, Rin Okuyama wrote:

Now, all *_crash_fpe tests pass for powerpc, and nothing changes for amd64
at least.


Here, powerpc means powerpc/oea, more specifically Mac mini G4.

At the moment, fenv.h doesn't work correctly on booke and ibm4xx, where FPU
is emulated in software. For some processors of oea, m[ft]msr instructions
used in fenv.h may be privileged, and need similar care as booke/ibm4xx.

Thanks,
rin


Re: CVS commit: src/external/gpl3/gcc

2020-06-02 Thread Rin Okuyama

On 2020/06/02 17:03, matthew green wrote:

Module Name:src
Committed By:   mrg
Date:   Tue Jun  2 08:03:59 UTC 2020

Modified Files:
src/external/gpl3/gcc: gcc2netbsd

Log Message:
don't elide fortran components.  we'd like to revive g77-as-gfortran.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/external/gpl3/gcc/gcc2netbsd

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


That sounds *REALLY* great!

I still use Fortran in my work ;).

Thanks,
rin


Re: CVS commit: src/sys/kern

2020-06-01 Thread Rin Okuyama

On 2020/06/02 2:08, Joerg Sonnenberger wrote:

On Sun, May 31, 2020 at 11:24:20PM +, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Sun May 31 23:24:20 UTC 2020

Modified Files:
src/sys/kern: kern_timeout.c

Log Message:
Stop allocating buffers dynamically in a DDB session, in order not to
disturb on-going debugged state of kernel datastructures.


This breaks the build with clang as it uses a declared-but-not-defined
type callout_cpu.


Fixed. Sorry for breakage.

Thanks,
rin


Re: CVS commit: src/sys/ddb

2020-05-31 Thread Rin Okuyama

On 2020/06/01 9:36, Kamil Rytarowski wrote:

If you can find a use-case today in DDB for an exclusive allocator. I
have it ready and tested.

I intended to use it in ddb for one project, but that project is still
unfinished.


Good to know! I will ask you when I want it!

Thanks,
rin


Re: CVS commit: src/sys/ddb

2020-05-31 Thread Rin Okuyama

On 2020/06/01 9:23, Kamil Rytarowski wrote:

I wrote a tiny malloc (libc-style) implementation over a small static
storage (could be over stack or preallocated on the heap) without any
external dependencies.

Would it be useful for you?


At the moment, we need buffers only in db_show_callout(), and static
buffers are enough there, IMO.

However, in future, if we want to add new features that require dynamic
buffer allocation, we need to implement exclusive allocator for DDB.

Thanks,
rin


Re: CVS commit: src/sys/uvm

2020-04-26 Thread Rin Okuyama

On 2020/04/27 11:47, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Apr 27 02:47:26 UTC 2020

Modified Files:
src/sys/uvm: uvm_extern.h

Log Message:
Add missing \ to fix build for PMAP_CACHE_VIVT, i.e., ARMv4 and prior.


s/v4/v5/


Re: CVS commit: src/sys/lib/libkern/arch/m68k

2020-04-22 Thread Rin Okuyama

In addition to these files in this mail:

Modified Files:
src/lib/libc/arch/m68k/gen: Makefile.inc
src/lib/libc/compiler_rt: Makefile.inc
src/sys/arch/sun68k/stand/libsa: Makefile.inc

Removed Files:
src/common/lib/libc/arch/m68k/gen: divsi3.S modsi3.S udivsi3.S umodsi3.S

However, cvs aborted since I forgot to ``cvs add'' and commit mail was
not sent. Sorry for the inconvenience...

Diffs are attached to this message.

Thanks,
rin

On 2020/04/22 20:58, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Wed Apr 22 11:58:26 UTC 2020

Added Files:
src/sys/lib/libkern/arch/m68k: divsi3.S modsi3.S udivsi3.S umodsi3.S

Log Message:
Restrict usage of m68k assembler versions of {,u}divsi3 and {,u}divsi3 to
kernel and bootloader for 68010.

They requires a special calling convention to udivsi3, and cannot to be
mixed up in normal routines provided by libgcc or compiler_rt. Although,
there's no problem for using in a controlled situation, i.e., kernel and
standalone programs.

Note that this does not affect m68k ports other than sun2, since codes
generated by gcc do not call these routines.

Assembler files are moved from common/lib/libc/arch/m68k/gen to
sys/lib/libkern/arch/m68k in order not to be compiled in libc.

Revert hack introduced to lib/libc/compiler_rt/Makefile.inc rev 1.37:
http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/compiler_rt/Makefile.inc#rev1.37

Proposed on port-sun2@ with no response...
(Again, this does not affect m68k ports other than sun2.)
http://mail-index.netbsd.org/port-sun2/2020/03/10/msg000102.html


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.3 src/sys/lib/libkern/arch/m68k/divsi3.S \
 src/sys/lib/libkern/arch/m68k/modsi3.S \
 src/sys/lib/libkern/arch/m68k/umodsi3.S
cvs rdiff -u -r0 -r1.5 src/sys/lib/libkern/arch/m68k/udivsi3.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Added files:

Index: src/sys/lib/libkern/arch/m68k/divsi3.S
diff -u /dev/null src/sys/lib/libkern/arch/m68k/divsi3.S:1.3
--- /dev/null   Wed Apr 22 11:58:26 2020
+++ src/sys/lib/libkern/arch/m68k/divsi3.S  Wed Apr 22 11:58:26 2020
@@ -0,0 +1,71 @@
+/* $NetBSD: divsi3.S,v 1.3 2020/04/22 11:58:26 rin Exp $   */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+   RCSID("from: @(#)divsi3.s  5.1 (Berkeley) 6/7/90")
+#else
+   RCSID("$NetBSD: divsi3.S,v 1.3 2020/04/22 11:58:26 rin Exp $")
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+/* int / int */
+#ifndef __mc68010__
+#error
+ENTRY(__divsi3)
+   movel   4(%sp),%d0
+   divsl   8(%sp),%d0
+   rts
+END(__divsi3)
+#else
+ENTRY(__divsi3)
+| NB: this requires that __udivsi3 preserve %a0:
+   movel   4(%sp), %d1 | load the dividend
+   bpl 1f
+   negl4(%sp)  | store abs(dividend)
+1: movel   8(%sp), %d0 | load the divisor
+   bpl 2f
+   negl8(%sp)  | store abs(divisor)
+2: eorl%d1, %d0
+   bpl 3f  | branch if sgn(divisor) == sgn(dividend)
+   movel   (%sp)+, %a0 | pop return address
+   pea (.Lret,%pc) 

Re: NO_KERNEL_RCSIDS

2020-04-22 Thread Rin Okuyama

On 2020/04/22 19:10, m...@netbsd.org wrote:

On Wed, Apr 22, 2020 at 09:23:21AM +, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Wed Apr 22 09:23:21 UTC 2020

Modified Files:
src/sys/sys: cdefs.h

Log Message:
For NO_KERNEL_RCSIDS, strip __RCSID() also for src/common/*.


Since these live in their own ELF section, wouldn't it be easier to use
strip(1) to remove them, than modify source code?



Well, I'm planning to add kernel option to strip non-global symbols
(mainly for sun2, which is suffering from severe memory shortage).
I will consider to re-implement NO_KERNEL_RCSIDS option in
sys/conf/Makefile.kern.inc, at the same time.

Thanks,
rin


Re: CVS commit: src/sys

2020-04-17 Thread Rin Okuyama

On 2020/04/17 22:14, Jason Thorpe wrote:



On Apr 17, 2020, at 12:24 AM, Robert Elz  wrote:

For this, RCS and RCS semantics are irrelevant aren't they?


No, not really.  With the modern systems, the "commit ID" identifies the state 
of the entire collection of files, not individual ones.  Thus, you only need exactly one 
instance of the ID, not one ID per file.


Exactly, but at the same time I think that RCSID is still useful till
we switch to a sane VCS with unique commit ID's.

The attached patch adds SHF_MERGE|SHF_STRINGS flags as Joerg suggested.
I've confirmed that it works fine both for GCC/binutils and LLVM (for
kernel and userland).

OK to commit, or objections?

Thanks,
rin
Index: sys/sys/cdefs_elf.h
===
RCS file: /home/netbsd/src/sys/sys/cdefs_elf.h,v
retrieving revision 1.55
diff -p -u -r1.55 cdefs_elf.h
--- sys/sys/cdefs_elf.h 22 Mar 2020 00:25:01 -  1.55
+++ sys/sys/cdefs_elf.h 17 Apr 2020 13:23:01 -
@@ -136,12 +136,12 @@
 
 #if __STDC__
 #define__SECTIONSTRING(_sec, _str) 
\
-   __asm(".pushsection " #_sec "\n"\
+   __asm(".pushsection " #_sec ", \"MS\", @progbits, 1\n"  \
  ".asciz \"" _str "\"\n"   \
  ".popsection")
 #else
 #define__SECTIONSTRING(_sec, _str) 
\
-   __asm(".pushsection _sec\n" \
+   __asm(".pushsection _sec, \"MS\", @progbits, 1\n"   \
  ".asciz \"" _str "\"\n"   \
  ".popsection")
 #endif


Re: CVS commit: src/sys

2020-04-16 Thread Rin Okuyama

On 2020/04/17 6:56, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Thu Apr 16 21:56:43 UTC 2020

Modified Files:
src/sys/arch/arm/omap: omap3_sdmareg.h omap3_sdmavar.h omapfbreg.h
src/sys/arch/arm/ti: omap3_dssreg.h
src/sys/arch/macppc/dev: batteryvar.h cudavar.h deqvar.h obiovar.h
platinumfbreg.h pmuvar.h valkyriefbreg.h videopllvar.h
src/sys/arch/mips/adm5120/dev: if_admswvar.h
src/sys/arch/powerpc/include: intr.h
src/sys/arch/powerpc/pic: ipivar.h picvar.h
src/sys/dev/acpi/wmi: wmi_acpivar.h
src/sys/dev/adb: adbvar.h
src/sys/dev/i2c: adm1026reg.h dbcool_reg.h dbcool_var.h sgsmixvar.h
src/sys/dev/ic: i128reg.h i128var.h
src/sys/dev/pci: gffbreg.h ppbvar.h voyagervar.h
src/sys/dev/qbus: rlvar.h
src/sys/external/bsd/ena-com: ena_plat.h
src/sys/lib/libkern: crc16.h
src/sys/ufs/ext2fs: ext2fs_xattr.h

Log Message:
Stop using __KERNEL_RCSID() in header files; it confuses ident(1) by
overwriting RCSID in main source files.

XXX
The first argument of __KERNEL_RCSID() is neglected for ELF. If we wish
to have RCSID of header files in kernel binary, we need something like
__FBSDID() macro in FreeBSD.


Oops, this description is not correct. __KERNEL_RCSID() in header files
does *not* overwrite RCSID in main source files. The problem is that it
inserts its own RCSID in *every* object files.

As a result, ident(1) shows more than 1000 duplicated lines for GENERIC
kernel of macppc, for example.

Thanks,
rin


Modularize sun2 kernel (Re: CVS commit: src/sys/arch/sun2/conf)

2020-03-14 Thread Rin Okuyama

(added port-sun2 and thorpej)

On 2020/03/08 17:40, matthew green wrote:

"Rin Okuyama" writes:

Module Name:src
Committed By:   rin
Date:   Sun Mar  8 06:25:10 UTC 2020

Modified Files:
src/sys/arch/sun2/conf: GENERIC

Log Message:
Retire md(4) in favor of tmpfs provided by module,
though both are not useful for 8MB RAM system...


...


it's cool you got modules on sun2 working... however, the
module version of a thing is going to use more real memory
than the built-in version, so i'm not sure where this is
going yet...


Sorry for the late reply. I was confused by weird kernel behaviors when
memory shortage. But, I think that I slowly came to understand that :).

Yes, modular kernel requires more memory, mainly because KERN_AS is
changed from ``library'' to ``obj'':

https://nxr.netbsd.org/xref/src/sys/lib/libkern/Makefile.inc#8

This pulls in all libkern routines to kernel.

However, I think that modularization is the only way to prolong sun2
port as far as I can tell.

We need to reduce kernel text as much as possible. This is because

(1) Our bootloader mapps only 2MB for kernel image.
(2) Even though bootloader can load kernel, it hangs here and there,
if kernel size is near 2MB.

For (1), our GENERIC is very close to this limit, even though almost
all additional features are stripped off. I managed to map more 128KB
memory, (maybe) not used by firmware, at least on TME:

http://www.netbsd.org/~rin/sun2_bootloader_20200315.patch

But I don't know whether it works or not on real hardwares.

(2) is more serious. When kernel hangs, it is trapped in pagedaemon.
I built a kernel with DIAGNOSTIC and LOCKDEBUG, but no failures are
detected. Now, I imagine its scenario as follows:

Our kernel allocates many memory on demand. Hangs may be the normal
operation (not a bug) when memory is allocated with KM_SLEEP or
M_WAITOK, but pagedaemon cannot free memory. Swap is not ready in
early boot stage, or all memory is wired, or thrashing takes place
like ping-pong; suppose two memory segments are required at the same
time. pagedaemon swaps out segment 1 to swap in segment 2, and
immediately after, it frees segment 2 to pull in segment 1.

Then, ``deadlock'' is effectively formed, which is cannot detected by
neither DIAGNOSTIC nor LOCKDEBUG.

Hangs due to (2) are remarkably mitigated by modularization. More
features can be loaded by modload(8), even if kernel stops working
when that are statically linked into kernel. This is because kernel
text is wired, whereas modules are pageable.


8MB?  luxury?  :)  i've been testing in 4MB tme :)


Sorry, s/8MB/7MB/ in the commit log. Framebuffer and etc. reside at
PA 0x70 and above.

I think that we can no longer support 4MB system because of (2); hangs
due to (2) are much more serious for 4MB system than it is in 7MB system.
Modern kernel allocates too much things on demand rather than statically
allocating them in data segment...

GENERIC became not working again due to (2) (even for 7MB). Can I go
further, i.e., strip more features that can be provided by modules, or
do you have any other ideas?

P.S.
In many cases of hangs due to (2), I can break into DDB from console.
However, in some cases, especially due to "ifconfig lo0 127.0.0.1" in
/etc/rc, it does not even accept input from console. I suspect that
someone in our network code allocates memory with KM_SLEEP or M_WAITOK
in the interrupt context, or with spl raised...

Thanks,
rin


Switch to compiler_rt from assembler codes? (Re: CVS commit: src/lib/libc/compiler_rt)

2020-03-10 Thread Rin Okuyama

(added port-sun2@)

On 2020/03/09 3:33, Joerg Sonnenberger wrote:

On Sun, Mar 08, 2020 at 06:30:06AM +, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Sun Mar  8 06:30:06 UTC 2020

Modified Files:
src/lib/libc/compiler_rt: Makefile.inc

Log Message:
Fix broken printf(3) %d output for numbers more than two digits, e.g.,

   printf("%d\n", 42) ---> "::" instead of "42"

Our __{,u}modsi3 codes assume that __udivsi3 returns remainder to
%d1 (volatile register). __udivsi3 in libgcc does not, and therefore
mixing them up results in mess.


This looks like the wrong fix to me. This is not about libgcc at all.
The depency in the src/common code should be fixed IMO. If __{,u}modsi3
wants to make assumptions about the remainder being implicitly computed,
it really should be using the divmod primitive instead.


Strictly speaking, this is bug in __{,u}modsi3. However:

(1) This is for optimization. There is no need for stack push and pop if
they can use our special version of __udivsi3, instead of __divmodsi4.
If they were ``fixed'' correctly, the resulted codes would have no big
difference from the C version provided by compiler_rt.

(2) Problems occur only when they are mixed with libgcc version of
__udivsi3. For standalone programs, i.e., kernel and bootloader, this
``wrong'' version works well.

(3) They are used only for m68000 (68010; sun2). For m68k (68020 and
later; other m68k ports), GCC does not generate references to these
functions at all.

Therefore, I propose:

(A) Continue to use these assembler codes only in standalone programs
(kernel and bootloader). For userland (libc), switch to the C version
provided by compiler_rt. Again, this affects only for 68010, i.e., sun2,
and not for other m68k ports.

Alternatively, we can:

(b) Switch both standalone and userland to compiler_rt.

I've checked both (A) and (B) version of live-image work fine on TME.
I prefer (A) over (B), since there is no problem if they are used only
in a controlled situation. Also, we are suffering from increase in
kernel size on sun2. But how do you everyone think?

Thanks,
rin


Re: CVS commit: src/lib/libc/compiler_rt

2020-03-07 Thread Rin Okuyama

Oops, forgot to note that this is only for 68010, and other
systems including m68k are not affected.

Thanks,
rin

On 2020/03/08 15:30, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Sun Mar  8 06:30:06 UTC 2020

Modified Files:
src/lib/libc/compiler_rt: Makefile.inc

Log Message:
Fix broken printf(3) %d output for numbers more than two digits, e.g.,

   printf("%d\n", 42) ---> "::" instead of "42"

Our __{,u}modsi3 codes assume that __udivsi3 returns remainder to
%d1 (volatile register). __udivsi3 in libgcc does not, and therefore
mixing them up results in mess.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libc/compiler_rt/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Modified files:

Index: src/lib/libc/compiler_rt/Makefile.inc
diff -u src/lib/libc/compiler_rt/Makefile.inc:1.36 
src/lib/libc/compiler_rt/Makefile.inc:1.37
--- src/lib/libc/compiler_rt/Makefile.inc:1.36  Tue Oct 29 16:08:50 2019
+++ src/lib/libc/compiler_rt/Makefile.inc   Sun Mar  8 06:30:06 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.36 2019/10/29 16:08:50 joerg Exp $
+# $NetBSD: Makefile.inc,v 1.37 2020/03/08 06:30:06 rin Exp $
  
  COMPILER_RT_SRCDIR=	${NETBSDSRCDIR}/sys/external/bsd/compiler_rt/dist
  
@@ -170,9 +170,16 @@ GENERIC_SRCS+= \

  GENERIC_SRCS+= \
divmodsi4.c \
divsi3.c \
-   modsi3.c \
udivmodsi4.c \
+
+. if ${LIBC_MACHINE_ARCH} != "m68000"
+# Our __{,u}modsi3 codes assume that __udivsi3 returns remainder to
+# %d1 (volatile register). __udivsi3 in libgcc does not, and therefore
+# mixing them up results in mess.
+GENERIC_SRCS+= \
+   modsi3.c \
umodsi3.c
+. endif
  
  . if ${LIBC_MACHINE_CPU} != "sh3"

  # On sh3 __udivsi3 is gcc "millicode" with special calling convention



Re: CVS commit: src/sys/kern

2020-03-02 Thread Rin Okuyama

Hi,

On 2020/03/03 1:00, Taylor R Campbell wrote:

Module Name:src
Committed By:   riastradh
Date:   Mon Mar  2 16:00:54 UTC 2020

Modified Files:
src/sys/kern: files.kern

Log Message:
Include kern_crashme.c in non-DEBUG kernels.

This is useful for simulating crashes in production to test failover.


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/kern/files.kern

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


I like this.

Could you please send pullup request to netbsd-9, or can I?

Thanks,
rin


Re: CVS commit: src/sys/arch/powerpc/powerpc

2020-02-19 Thread Rin Okuyama

On 2020/02/18 6:55, Andrew Doran wrote:

I corrected the cpu_ast() case.  Yes it's curious why ibm4xx calls
mi_userret() directly; that seems wrong (I have not changed it though).  I
think it definitely makes more sense to deal with OWEUPC before userret().


Thank you!

Now, I'm working on fixing ibm4xx. IMO, there's no reason to use
mi_userret() here, and I will commit a fix later with other commits.

Thanks,
rin


Re: CVS commit: src/sys/arch/powerpc/powerpc

2020-02-04 Thread Rin Okuyama

Hi,

On 2019/12/06 5:55, Andrew Doran wrote:

Module Name:src
Committed By:   ad
Date:   Thu Dec  5 20:55:24 UTC 2019

Modified Files:
src/sys/arch/powerpc/powerpc: powerpc_machdep.c

Log Message:
Need to call userret() from cpu_ast().


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/arch/powerpc/powerpc/powerpc_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Modified files:

Index: src/sys/arch/powerpc/powerpc/powerpc_machdep.c
diff -u src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.74 
src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.75
--- src/sys/arch/powerpc/powerpc/powerpc_machdep.c:1.74 Sat Nov 23 19:40:36 2019
+++ src/sys/arch/powerpc/powerpc/powerpc_machdep.c  Thu Dec  5 20:55:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: powerpc_machdep.c,v 1.74 2019/11/23 19:40:36 ad Exp $  */
+/* $NetBSD: powerpc_machdep.c,v 1.75 2019/12/05 20:55:24 ad Exp $  */
  
  /*

   * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
   */
  
  #include 

-__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.74 2019/11/23 19:40:36 ad Exp 
$");
+__KERNEL_RCSID(0, "$NetBSD: powerpc_machdep.c,v 1.75 2019/12/05 20:55:24 ad Exp 
$");
  
  #include "opt_altivec.h"

  #include "opt_ddb.h"
@@ -373,6 +373,8 @@ void
  cpu_ast(struct lwp *l, struct cpu_info *ci)
  {
l->l_md.md_astpending = 0;   /* we are about to do it */
+   __insn_barrier();
+   userret(l, l->l_md.md_utf);
  
  	if (l->l_pflag & LP_OWEUPC) {

l->l_pflag &= ~LP_OWEUPC;
@@ -400,7 +402,7 @@ cpu_need_resched(struct cpu_info *ci, st
cpu_send_ipi(cpu_index(ci), IPI_AST);
  #endif
} else {
-   l->l_md.md_astpending = 1;   /* force call to ast() */
+   l->l_md.md_astpending = 1;   /* force call to cpu_ast() */
}
  }
  



This commit makes userret() called twice with AST; cpu_ast() is
invoked from

booke/trap.c,
https://nxr.netbsd.org/xref/src/sys/arch/powerpc/booke/trap.c#815

ibm4xx/trap.c, and
https://nxr.netbsd.org/xref/src/sys/arch/powerpc/ibm4xx/trap.c#276

powerpc/trap.c.
https://nxr.netbsd.org/xref/src/sys/arch/powerpc/powerpc/trap.c#348

For all cases, userret() is called afterward. (Precisely speaking,
for ibm4xx, mi_userret(9) is used instead. This should probably be
replaced by userret().)

Also, other ports test (l->l_pflag & LP_OWEUPC) before mi_userret(9).

Thanks,
rin


CVS commit: src/external/gpl3/binutils/dist/bfd

2019-11-30 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Nov 30 22:50:11 UTC 2019

Modified Files:
src/external/gpl3/binutils/dist/bfd: elf.c

Log Message:
Fix 'nm /dev/ksyms' (noticed by ryo).

Since binutils 2.15, nm(1) cannot be used for character devices.
We worked around this by a local patch:

http://cvsweb.netbsd.org/bsdweb.cgi/src/gnu/dist/binutils/binutils/Attic/bucomm.c?r1=1.1.1.2=0#rev1.2

With recent update of binutils, 'nm /dev/ksyms' got broken again.
This is due to a consistency check involving file size reported by
stat(2), which is always zero for character devices. So, skip this
check if file size is zero.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/external/gpl3/binutils/dist/bfd/elf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/external/gpl3/binutils/dist/bfd/elf.c
diff -u src/external/gpl3/binutils/dist/bfd/elf.c:1.13 src/external/gpl3/binutils/dist/bfd/elf.c:1.14
--- src/external/gpl3/binutils/dist/bfd/elf.c:1.13	Wed Nov  7 01:13:52 2018
+++ src/external/gpl3/binutils/dist/bfd/elf.c	Sat Nov 30 22:50:11 2019
@@ -298,7 +298,8 @@ bfd_elf_get_str_section (bfd *abfd, unsi
   /* Allocate and clear an extra byte at the end, to prevent crashes
 	 in case the string table is not terminated.  */
   if (shstrtabsize + 1 <= 1
-	  || shstrtabsize > bfd_get_file_size (abfd)
+	  || (bfd_get_file_size (abfd) > 0 /* not a character device */
+		&& shstrtabsize > bfd_get_file_size (abfd))
 	  || bfd_seek (abfd, offset, SEEK_SET) != 0
 	  || (shstrtab = (bfd_byte *) bfd_alloc (abfd, shstrtabsize + 1)) == NULL)
 	shstrtab = NULL;



CVS commit: src/external/gpl3/binutils/dist/bfd

2019-11-30 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Nov 30 22:50:11 UTC 2019

Modified Files:
src/external/gpl3/binutils/dist/bfd: elf.c

Log Message:
Fix 'nm /dev/ksyms' (noticed by ryo).

Since binutils 2.15, nm(1) cannot be used for character devices.
We worked around this by a local patch:

http://cvsweb.netbsd.org/bsdweb.cgi/src/gnu/dist/binutils/binutils/Attic/bucomm.c?r1=1.1.1.2=0#rev1.2

With recent update of binutils, 'nm /dev/ksyms' got broken again.
This is due to a consistency check involving file size reported by
stat(2), which is always zero for character devices. So, skip this
check if file size is zero.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/external/gpl3/binutils/dist/bfd/elf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/kern

2019-11-30 Thread Rin Okuyama

On 2019/11/30 23:35, Andrew Doran wrote:

Hmm, it works fine on amd64 and looks OK but me, but I have backed it out
for the time being.


Thanks! Also thank you for working on this area!

rin


Re: CVS commit: src/sys/kern

2019-11-29 Thread Rin Okuyama

On 2019/11/30 5:50, Andrew Doran wrote:

Module Name:src
Committed By:   ad
Date:   Fri Nov 29 20:50:54 UTC 2019

Modified Files:
src/sys/kern: kern_rwlock.c

Log Message:
A couple more tweaks to avoid reading the lock word.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/kern_rwlock.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


Hi,

After this commit, GENERIC64 kernel on evbarm-aarch64 does no longer
boot multiuser anymore with rwlock related panics:

panic: kernel diagnostic assertion "vm_map_locked_p(map)" failed: file 
"../../../../uvm/uvm_map.c", line 1315

or

panic: kernel diagnostic assertion "rw_write_held(>lock)" failed: file 
"../../../../uvm/uvm_map.c", line 701

By reverting kern_rwlock.c to rev 1.56, panics disappear as far as
I can see.

Thanks,
rin

...
Starting nfsd.
[  24.5728628] panic: kernel diagnostic assertion "vm_map_locked_p(map)" failed: file 
"../../../../uvm/uvm_map.c", line 1315
[  24.5880334] cpu0: Begin traceback...
[  24.5880334] trace fp ffc033453aa0
[  24.5954047] fp ffc033453ac0 vpanic() at ffc0004892d0 
netbsd:vpanic+0x160
[  24.6054105] fp ffc033453b30 kern_assert() at ffc0005bc1ac 
netbsd:kern_assert+0x5c
[  24.6154460] fp ffc033453bc0 uvm_map_enter() at ffc000402fb0 
netbsd:uvm_map_enter+0x3b8
[  24.6254813] fp ffc033453c60 uvm_map() at ffc00040351c 
netbsd:uvm_map+0x9c
[  24.6355640] fp ffc033453cf0 uvm_mmap.part.0() at ffc000405ccc 
netbsd:uvm_mmap.part.0+0x13c
[  24.6454881] fp ffc033453d70 sys_mmap() at ffc000406390 
netbsd:sys_mmap+0x1d8
[  24.6570928] fp ffc033453e20 syscall() at ffc787dc 
netbsd:syscall+0x18c
[  24.6683611] tf ffc033453ed0 el0_trap() at ffc76e88 
netbsd:el0_trap
[  24.6794682]  trapframe 0xffc033453ed0 (304 bytes) 
...

...
Starting postfix.
[  30.0175876] panic: kernel diagnostic assertion "rw_write_held(>lock)" failed: 
file "../../../../uvm/uvm_map.c", line 701
[  30.0275865] cpu1: Begin traceback...
[  30.0275865] trace fp ffc034b0edf0
[  30.0375913] fp ffc034b0ee10 vpanic() at ffc0004892d0 
netbsd:vpanic+0x160
[  30.0475892] fp ffc034b0ee80 kern_assert() at ffc0005bc1ac 
netbsd:kern_assert+0x5c
[  30.0575897] fp ffc034b0ef10 vm_map_unlock() at ffc0003ff6c4 
netbsd:vm_map_unlock+0x94
[  30.0675928] fp ffc034b0ef30 uvm_map_enter() at ffc000402f04 
netbsd:uvm_map_enter+0x30c
[  30.0775928] fp ffc034b0efd0 uvm_map() at ffc00040351c 
netbsd:uvm_map+0x9c
[  30.0775928] fp ffc034b0f060 uvm_pagermapin() at ffc00040b69c 
netbsd:uvm_pagermapin+0xac
[  30.0975934] fp ffc034b0f0e0 genfs_getpages() at ffc0004f5ff8 
netbsd:genfs_getpages+0xbb8
[  30.1075948] fp ffc034b0f270 VOP_GETPAGES() at ffc0004f38b4 
netbsd:VOP_GETPAGES+0x44
[  30.1175956] fp ffc034b0f2e0 ubc_fault() at ffc0003f6f30 
netbsd:ubc_fault+0x168
[  30.1275959] fp ffc034b0f370 uvm_fault_internal() at ffc0003f9a18 
netbsd:uvm_fault_internal+0x478
[  30.1375967] fp ffc034b0f580 data_abort_handler() at ffc79f88 
netbsd:data_abort_handler+0x100
[  30.1475968] tf ffc034b0f600 el1_trap() at ffc76e24 
netbsd:el1_trap
[  30.1575982]  trapframe 0xffc034b0f600 (304 bytes) 
...


CVS commit: src/sys/arch/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:16:59 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c
src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h

Log Message:
Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/amd64/amd64/process_machdep.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/include/netbsd32_machdep.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/netbsd32_machdep.c
diff -u src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.131 src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.132
--- src/sys/arch/amd64/amd64/netbsd32_machdep.c:1.131	Wed Nov 20 19:37:51 2019
+++ src/sys/arch/amd64/amd64/netbsd32_machdep.c	Wed Nov 27 09:16:58 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.131 2019/11/20 19:37:51 pgoyette Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.132 2019/11/27 09:16:58 rin Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.131 2019/11/20 19:37:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.132 2019/11/27 09:16:58 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -86,6 +86,9 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac
 const char machine32[] = "i386";
 const char machine_arch32[] = "i386";
 
+static int netbsd32_process_doxmmregs(struct lwp *, struct lwp *, void *, bool);
+static int netbsd32_process_xmmregio(struct lwp *, struct lwp *, struct uio *);
+
 #ifdef USER_LDT
 static int x86_64_get_ldt32(struct lwp *, void *, register_t *);
 static int x86_64_set_ldt32(struct lwp *, void *, register_t *);
@@ -344,8 +347,8 @@ netbsd32_ptrace_translate_request(int re
 	case PT32_SETREGS:		return PT_SETREGS;
 	case PT32_GETFPREGS:		return PT_GETFPREGS;
 	case PT32_SETFPREGS:		return PT_SETFPREGS;
-	case PT32_GETXMMREGS:		return -1;
-	case PT32_SETXMMREGS:		return -1;
+	case PT32_GETXMMREGS:		return PT_GETXMMREGS;
+	case PT32_SETXMMREGS:		return PT_SETXMMREGS;
 	case PT32_GETDBREGS:		return PT_GETDBREGS;
 	case PT32_SETDBREGS:		return PT_SETDBREGS;
 	case PT32_SETSTEP:		return PT_SETSTEP;
@@ -500,6 +503,77 @@ netbsd32_process_write_dbregs(struct lwp
 	return 0;
 }
 
+static int
+netbsd32_process_doxmmregs(struct lwp *curl, struct lwp *l, void *addr,
+bool write)
+	/* curl:		 tracer */
+	/* l:			 traced */
+{
+	struct uio uio;
+	struct iovec iov;
+	struct vmspace *vm;
+	int error;
+
+	if ((curl->l_proc->p_flag & PK_32) == 0 ||
+	(l->l_proc->p_flag & PK_32) == 0)
+		return EINVAL;
+
+	if (!process_machdep_validfpu(l->l_proc))
+		return EINVAL;
+
+	error = proc_vmspace_getref(curl->l_proc, );
+	if (error)
+		return error;
+
+	iov.iov_base = addr;
+	iov.iov_len = sizeof(struct xmmregs32);
+	uio.uio_iov = 
+	uio.uio_iovcnt = 1;
+	uio.uio_offset = 0;
+	uio.uio_resid = sizeof(struct xmmregs32);
+	uio.uio_rw = write ? UIO_WRITE : UIO_READ;
+	uio.uio_vmspace = vm;
+
+	error = netbsd32_process_xmmregio(curl, l, );
+	uvmspace_free(vm);
+	return error;
+}
+
+static int
+netbsd32_process_xmmregio(struct lwp *curl, struct lwp *l, struct uio *uio)
+	/* curl:		 tracer */
+	/* l:			 traced */
+{
+	struct xmmregs32 regs;
+	int error;
+	char *kv;
+	size_t kl;
+
+	kl = sizeof(regs);
+	kv = (char *)
+
+	if (uio->uio_offset < 0 || uio->uio_offset > (off_t)kl)
+		return EINVAL;
+
+	kv += uio->uio_offset;
+	kl -= uio->uio_offset;
+
+	if (kl > uio->uio_resid)
+		kl = uio->uio_resid;
+
+	process_read_fpregs_xmm(l, );
+	error = uiomove(kv, kl, uio);
+	if (error == 0 && uio->uio_rw == UIO_WRITE) {
+		if (l->l_proc->p_stat != SSTOP)
+			error = EBUSY;
+		else
+			process_write_fpregs_xmm(l, );
+	}
+
+	uio->uio_offset = 0;
+	return error;
+}
+
 int
 netbsd32_sysarch(struct lwp *l, const struct netbsd32_sysarch_args *uap, register_t *retval)
 {
@@ -959,6 +1033,8 @@ netbsd32_machdep_md_init(void)
 	MODULE_HOOK_SET(netbsd32_machine32_hook, "mach32", netbsd32_machine32);
 	MODULE_HOOK_SET(netbsd32_reg_validate_hook,
 	"mcontext32from64_validate", cpu_mcontext32from64_validate);
+	MODULE_HOOK_SET(netbsd32_process_doxmmregs_hook, "xmm32",
+	netbsd32_process_doxmmregs);
 }
 
 void
@@ -967,4 +1043,5 @@ netbsd32_machdep_md_fini(void)
 
 	MODULE_HOOK_UNSET(netbsd32_machine32_hook);
 	MODULE_HOOK_UNSET(netbsd32_reg_validate_hook);
+	MODULE_HOOK_UNSET(netbsd32_process_doxmmregs_hook);
 }

Index: 

CVS commit: src/sys/arch/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:16:59 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c process_machdep.c
src/sys/arch/amd64/include: netbsd32_machdep.h ptrace.h

Log Message:
Add support for PT_[GS]ETXMMREGS requests for COMPAT_NETBSD32 on amd64.

For this purpose, PT_[GS]ETXMMREGS are added to amd64/ptrace.h. These
are intended for internal usage for COMPAT_NETBSD32, and therefore not
exposed to userland.

Thanks to kamil, mgorny, and pgoyette for their kind review!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/amd64/amd64/netbsd32_machdep.c
cvs rdiff -u -r1.46 -r1.47 src/sys/arch/amd64/amd64/process_machdep.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/amd64/include/netbsd32_machdep.h
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:08:14 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c
src/sys/arch/amd64/include: ptrace.h

Log Message:
Rename process_machdep_validxstate() to process_machdep_validfpu(), as
this function will be used to check validity of XMM registers also.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/amd64/amd64/process_machdep.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.45 src/sys/arch/amd64/amd64/process_machdep.c:1.46
--- src/sys/arch/amd64/amd64/process_machdep.c:1.45	Wed Nov 27 09:01:59 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Wed Nov 27 09:08:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.46 2019/11/27 09:08:14 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.46 2019/11/27 09:08:14 rin Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -324,7 +324,7 @@ ptrace_machdep_dorequest(
 		/* FALLTHROUGH */
 	case PT_GETXSTATE:
 		/* write = false done above. */
-		if (!process_machdep_validxstate(lt->l_proc))
+		if (!process_machdep_validfpu(lt->l_proc))
 			return EINVAL;
 		if (__predict_false(l->l_proc->p_flag & PK_32)) {
 			struct netbsd32_iovec user_iov;
@@ -404,7 +404,7 @@ process_machdep_doxstate(struct lwp *cur
 }
 
 int
-process_machdep_validxstate(struct proc *p)
+process_machdep_validfpu(struct proc *p)
 {
 
 	if (p->p_flag & PK_SYSTEM)

Index: src/sys/arch/amd64/include/ptrace.h
diff -u src/sys/arch/amd64/include/ptrace.h:1.17 src/sys/arch/amd64/include/ptrace.h:1.18
--- src/sys/arch/amd64/include/ptrace.h:1.17	Wed Nov 27 08:56:00 2019
+++ src/sys/arch/amd64/include/ptrace.h	Wed Nov 27 09:08:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.17 2019/11/27 08:56:00 rin Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.18 2019/11/27 09:08:14 rin Exp $	*/
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -88,7 +88,7 @@
 	case PT_SETXSTATE:
 
 int process_machdep_doxstate(struct lwp *, struct lwp *, struct uio *);
-int process_machdep_validxstate(struct proc *);
+int process_machdep_validfpu(struct proc *);
 
 #endif /* _KERNEL */
 



CVS commit: src/sys/arch/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:08:14 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c
src/sys/arch/amd64/include: ptrace.h

Log Message:
Rename process_machdep_validxstate() to process_machdep_validfpu(), as
this function will be used to check validity of XMM registers also.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/amd64/amd64/process_machdep.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/amd64/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:02:00 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Use bool for "write" in ptrace_machdep_dorequest() for clarity.
No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/process_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/amd64/amd64

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 09:02:00 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: process_machdep.c

Log Message:
Use bool for "write" in ptrace_machdep_dorequest() for clarity.
No functional changes.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/amd64/amd64/process_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.44 src/sys/arch/amd64/amd64/process_machdep.c:1.45
--- src/sys/arch/amd64/amd64/process_machdep.c:1.44	Tue Aug  6 01:34:29 2019
+++ src/sys/arch/amd64/amd64/process_machdep.c	Wed Nov 27 09:01:59 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -74,7 +74,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.44 2019/08/06 01:34:29 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.45 2019/11/27 09:01:59 rin Exp $");
 
 #include "opt_xen.h"
 #include 
@@ -315,15 +315,15 @@ ptrace_machdep_dorequest(
 	struct iovec iov;
 	struct vmspace *vm;
 	int error;
-	int write = 0;
+	bool write = false;
 
 	switch (req) {
 	case PT_SETXSTATE:
-		write = 1;
+		write = true;
 
 		/* FALLTHROUGH */
 	case PT_GETXSTATE:
-		/* write = 0 done above. */
+		/* write = false done above. */
 		if (!process_machdep_validxstate(lt->l_proc))
 			return EINVAL;
 		if (__predict_false(l->l_proc->p_flag & PK_32)) {



CVS commit: src/sys/arch/amd64/include

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 08:56:00 UTC 2019

Modified Files:
src/sys/arch/amd64/include: ptrace.h

Log Message:
Fix copy-paste in comment. No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/amd64/include

2019-11-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 27 08:56:00 UTC 2019

Modified Files:
src/sys/arch/amd64/include: ptrace.h

Log Message:
Fix copy-paste in comment. No binary changes.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/arch/amd64/include/ptrace.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/include/ptrace.h
diff -u src/sys/arch/amd64/include/ptrace.h:1.16 src/sys/arch/amd64/include/ptrace.h:1.17
--- src/sys/arch/amd64/include/ptrace.h:1.16	Wed Jun 26 12:30:12 2019
+++ src/sys/arch/amd64/include/ptrace.h	Wed Nov 27 08:56:00 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ptrace.h,v 1.16 2019/06/26 12:30:12 mgorny Exp $	*/
+/*	$NetBSD: ptrace.h,v 1.17 2019/11/27 08:56:00 rin Exp $	*/
 
 /*
  * Copyright (c) 1993 Christopher G. Demetriou
@@ -34,7 +34,7 @@
 
 #ifdef __x86_64__
 /*
- * i386-dependent ptrace definitions
+ * amd64-dependent ptrace definitions
  */
 #define	PT_STEP			(PT_FIRSTMACH + 0)
 #define	PT_GETREGS		(PT_FIRSTMACH + 1)



CVS commit: src/sys/arch/aarch64/aarch64

2019-11-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 11:45:00 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c

Log Message:
part of PR port-arm/54702

Make sure that md_march32 and ep_machine_arch have same size.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/aarch64/exec_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64/aarch64

2019-11-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 11:45:00 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c

Log Message:
part of PR port-arm/54702

Make sure that md_march32 and ep_machine_arch have same size.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/aarch64/aarch64/exec_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/exec_machdep.c
diff -u src/sys/arch/aarch64/aarch64/exec_machdep.c:1.5 src/sys/arch/aarch64/aarch64/exec_machdep.c:1.6
--- src/sys/arch/aarch64/aarch64/exec_machdep.c:1.5	Sun Nov 24 04:08:36 2019
+++ src/sys/arch/aarch64/aarch64/exec_machdep.c	Sun Nov 24 11:45:00 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_machdep.c,v 1.5 2019/11/24 04:08:36 rin Exp $ */
+/* $NetBSD: exec_machdep.c,v 1.6 2019/11/24 11:45:00 rin Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: exec_machdep.c,v 1.5 2019/11/24 04:08:36 rin Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_machdep.c,v 1.6 2019/11/24 11:45:00 rin Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_compat_netbsd32.h"
@@ -86,6 +86,8 @@ aarch64_netbsd_elf32_probe(struct lwp *l
 	/*
 	 * Copy (if any) the machine_arch of the executable to the proc.
 	 */
+	CTASSERT(sizeof(l->l_proc->p_md.md_march32) ==
+	sizeof(epp->ep_machine_arch));
 	if (epp->ep_machine_arch[0] != 0)
 		strlcpy(l->l_proc->p_md.md_march32, epp->ep_machine_arch,
 		sizeof(l->l_proc->p_md.md_march32));



CVS commit: src/sys/arch/aarch64/include

2019-11-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 11:28:40 UTC 2019

Modified Files:
src/sys/arch/aarch64/include: proc.h

Log Message:
part of PR port-arm/54702

Having md_march32 unconditionally in struct mdproc, in order to
make libkvm happy.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/include/proc.h
diff -u src/sys/arch/aarch64/include/proc.h:1.4 src/sys/arch/aarch64/include/proc.h:1.5
--- src/sys/arch/aarch64/include/proc.h:1.4	Sun Nov 24 04:08:36 2019
+++ src/sys/arch/aarch64/include/proc.h	Sun Nov 24 11:28:40 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: proc.h,v 1.4 2019/11/24 04:08:36 rin Exp $ */
+/* $NetBSD: proc.h,v 1.5 2019/11/24 11:28:40 rin Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -47,9 +47,7 @@ struct mdlwp {
 
 struct mdproc {
 	void (*md_syscall)(struct trapframe *);
-#ifdef COMPAT_NETBSD32
 	char md_march32[12];	/* machine arch of executable */
-#endif
 };
 
 #ifdef COMPAT_NETBSD32



CVS commit: src/sys/arch/aarch64/include

2019-11-24 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 11:28:40 UTC 2019

Modified Files:
src/sys/arch/aarch64/include: proc.h

Log Message:
part of PR port-arm/54702

Having md_march32 unconditionally in struct mdproc, in order to
make libkvm happy.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/include/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/aarch64

2019-11-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 04:08:36 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c netbsd32_machdep.c trap.c
src/sys/arch/aarch64/include: netbsd32_machdep.h param.h proc.h

Log Message:
PR port-arm/54702

Add support for earmv6hf binaries on COMPAT_NETBSD32 for aarch64:

- Emulate ARMv6 instructions with cache operations register (c7), that
  are deprecated since ARMv7, and disabled on ARMv8 with LP64 kernel.

- ep_machine_arch (default: earmv7hf) is copied from executables, as we
  do for mips64. "uname -p" reports earmv6hf if compiled for earmv6hf;
  configure scripts etc can determine the appropriate architecture.

Many thanks to ryo@ for helping me to add support of Thumb-mode,
as well as providing exhaustive test cases:

  https://github.com/ryo/mcr_test/

We've confirmed:

- Emulation works in Thumb-mode.
- T32 16-bit length illegal instruction results in SIGILL, even if
  it is located nearby a boundary b/w mapped and unmapped pages.
- T32 32-bit instruction results in SIGSEGV if it is located across
  a boundary b/w mapped and unmapped pages.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/aarch64/exec_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/include/netbsd32_machdep.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/include/param.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/aarch64/aarch64/exec_machdep.c
diff -u src/sys/arch/aarch64/aarch64/exec_machdep.c:1.4 src/sys/arch/aarch64/aarch64/exec_machdep.c:1.5
--- src/sys/arch/aarch64/aarch64/exec_machdep.c:1.4	Wed Nov 28 08:12:15 2018
+++ src/sys/arch/aarch64/aarch64/exec_machdep.c	Sun Nov 24 04:08:36 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_machdep.c,v 1.4 2018/11/28 08:12:15 ryo Exp $ */
+/* $NetBSD: exec_machdep.c,v 1.5 2019/11/24 04:08:36 rin Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: exec_machdep.c,v 1.4 2018/11/28 08:12:15 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_machdep.c,v 1.5 2019/11/24 04:08:36 rin Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_compat_netbsd32.h"
@@ -83,6 +83,13 @@ aarch64_netbsd_elf32_probe(struct lwp *l
 	ID_AA64PFR0_EL1_EL0_64_32)
 		return ENOEXEC;
 
+	/*
+	 * Copy (if any) the machine_arch of the executable to the proc.
+	 */
+	if (epp->ep_machine_arch[0] != 0)
+		strlcpy(l->l_proc->p_md.md_march32, epp->ep_machine_arch,
+		sizeof(l->l_proc->p_md.md_march32));
+
 	return 0;
 }
 #endif

Index: src/sys/arch/aarch64/aarch64/netbsd32_machdep.c
diff -u src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.8 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.9
--- src/sys/arch/aarch64/aarch64/netbsd32_machdep.c:1.8	Wed Nov 20 19:37:51 2019
+++ src/sys/arch/aarch64/aarch64/netbsd32_machdep.c	Sun Nov 24 04:08:36 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_machdep.c,v 1.8 2019/11/20 19:37:51 pgoyette Exp $	*/
+/*	$NetBSD: netbsd32_machdep.c,v 1.9 2019/11/24 04:08:36 rin Exp $	*/
 
 /*
  * Copyright (c) 2018 Ryo Shimizu 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.8 2019/11/20 19:37:51 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_machdep.c,v 1.9 2019/11/24 04:08:36 rin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -55,11 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_mac
 #include 
 
 const char machine32[] = MACHINE;
-#ifdef __AARCH64EB__
-const char machine_arch32[] = "earmv7hfeb";
-#else
-const char machine_arch32[] = "earmv7hf";
-#endif
+const char machine_arch32[] = MACHINE32_ARCH;
 
 void
 netbsd32_setregs(struct lwp *l, struct exec_package *pack, vaddr_t stack)

Index: src/sys/arch/aarch64/aarch64/trap.c
diff -u src/sys/arch/aarch64/aarch64/trap.c:1.20 src/sys/arch/aarch64/aarch64/trap.c:1.21
--- src/sys/arch/aarch64/aarch64/trap.c:1.20	Thu Nov 21 19:23:58 2019
+++ src/sys/arch/aarch64/aarch64/trap.c	Sun Nov 24 04:08:36 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.20 2019/11/21 19:23:58 ad Exp $ */
+/* $NetBSD: trap.c,v 1.21 2019/11/24 04:08:36 rin Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 
-__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.20 2019/11/21 19:23:58 ad Exp $");
+__KERNEL_RCSID(1, "$NetBSD: trap.c,v 1.21 2019/11/24 04:08:36 rin Exp $");
 
 #include "opt_arm_intr_impl.h"
 #include "opt_compat_netbsd32.h"
@@ -321,6 +321,103 @@ interrupt(struct trapframe *tf)
 	cpu_dosoftints();
 }
 
+#ifdef COMPAT_NETBSD32
+
+/*
+ * 32-bit length Thumb instruction. See ARMv7 DDI0406A A6.3.
+ */
+#define THUMB_32BIT(hi) (((hi) & 0xe000) == 0xe000 && 

CVS commit: src/sys/arch/aarch64

2019-11-23 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 24 04:08:36 UTC 2019

Modified Files:
src/sys/arch/aarch64/aarch64: exec_machdep.c netbsd32_machdep.c trap.c
src/sys/arch/aarch64/include: netbsd32_machdep.h param.h proc.h

Log Message:
PR port-arm/54702

Add support for earmv6hf binaries on COMPAT_NETBSD32 for aarch64:

- Emulate ARMv6 instructions with cache operations register (c7), that
  are deprecated since ARMv7, and disabled on ARMv8 with LP64 kernel.

- ep_machine_arch (default: earmv7hf) is copied from executables, as we
  do for mips64. "uname -p" reports earmv6hf if compiled for earmv6hf;
  configure scripts etc can determine the appropriate architecture.

Many thanks to ryo@ for helping me to add support of Thumb-mode,
as well as providing exhaustive test cases:

  https://github.com/ryo/mcr_test/

We've confirmed:

- Emulation works in Thumb-mode.
- T32 16-bit length illegal instruction results in SIGILL, even if
  it is located nearby a boundary b/w mapped and unmapped pages.
- T32 32-bit instruction results in SIGSEGV if it is located across
  a boundary b/w mapped and unmapped pages.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/aarch64/aarch64/exec_machdep.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/aarch64/aarch64/netbsd32_machdep.c
cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/aarch64/trap.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/aarch64/include/netbsd32_machdep.h
cvs rdiff -u -r1.12 -r1.13 src/sys/arch/aarch64/include/param.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/aarch64/include/proc.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Nov 22 05:01:44 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Fix regression introduced to ptrace_regs() in rev 1.27:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys_ptrace_common.c#rev1.27

Size of registers should be determined from tracer, NOT tracee.

Now, 64-bit tracer can manipulate registers of 32-bit tracee again.
gdb for amd64 works for i386 binaries to some extent.

XXX
pullup to netbsd-9 and -8.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-21 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Nov 22 05:01:44 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Fix regression introduced to ptrace_regs() in rev 1.27:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/sys_ptrace_common.c#rev1.27

Size of registers should be determined from tracer, NOT tracee.

Now, 64-bit tracer can manipulate registers of 32-bit tracee again.
gdb for amd64 works for i386 binaries to some extent.

XXX
pullup to netbsd-9 and -8.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.72 src/sys/kern/sys_ptrace_common.c:1.73
--- src/sys/kern/sys_ptrace_common.c:1.72	Sun Nov 17 02:22:14 2019
+++ src/sys/kern/sys_ptrace_common.c	Fri Nov 22 05:01:44 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.72 2019/11/17 02:22:14 rin Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.73 2019/11/22 05:01:44 rin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.72 2019/11/17 02:22:14 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.73 2019/11/22 05:01:44 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -831,9 +831,12 @@ ptrace_regs(struct lwp *l, struct lwp **
 void *addr, size_t data)
 {
 	int error;
-	struct proc *t = (*lt)->l_proc;
+	struct proc *p, *t;
 	struct vmspace *vm;
 
+	p = l->l_proc;		/* tracer */
+	t = (*lt)->l_proc;	/* traced */
+
 	if ((error = ptrace_update_lwp(t, lt, data)) != 0)
 		return error;
 
@@ -849,7 +852,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETREGS
 		if (!process_validregs(*lt))
 			return EINVAL;
-		size = PROC_REGSZ(t);
+		size = PROC_REGSZ(p);
 		func = ptm->ptm_doregs;
 		break;
 #endif
@@ -858,7 +861,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETFPREGS
 		if (!process_validfpregs(*lt))
 			return EINVAL;
-		size = PROC_FPREGSZ(t);
+		size = PROC_FPREGSZ(p);
 		func = ptm->ptm_dofpregs;
 		break;
 #endif
@@ -867,7 +870,7 @@ ptrace_regs(struct lwp *l, struct lwp **
 	case_PT_SETDBREGS
 		if (!process_validdbregs(*lt))
 			return EINVAL;
-		size = PROC_DBREGSZ(t);
+		size = PROC_DBREGSZ(p);
 		func = ptm->ptm_dodbregs;
 		break;
 #endif



CVS commit: src/sys/arch/amd64/amd64

2019-11-20 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Nov 20 10:57:08 UTC 2019

Modified Files:
src/sys/arch/amd64/amd64: netbsd32_machdep.c

Log Message:
Fix netbsd32_process_write_dbregs() for amd64:

- Zero-clear regs64 so that random values are not written into the
  preserved registers.
- Cast 32-bit registers (int) to u_int, in order to avoid undesired
  sign extension when filled into 64-bit registers (long).

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/arch/amd64/amd64/netbsd32_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 12:06:26 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h
src/sys/compat/sys: siginfo.h

Log Message:
8-byte objects on i386 or arm-oabi are aligned in 4-byte boundary.
Therefore, we must use __attribute__((__aligned__(4))) for them.
netbsd32_{,u}int64 are provided for this purpose. However, we
cannot use it in  due to circular dependency
b/w .

In order to distangle it, we choose here to have a duplicate type,
netbsd32_siginfo_uint64, in . The equivalence
with netbsd32_uint64 is asserted in .

Now, gdb for i386 works again on amd64 kernel.

Based on patch provided by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.8 -r1.9 src/sys/compat/sys/siginfo.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 12:06:26 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h
src/sys/compat/sys: siginfo.h

Log Message:
8-byte objects on i386 or arm-oabi are aligned in 4-byte boundary.
Therefore, we must use __attribute__((__aligned__(4))) for them.
netbsd32_{,u}int64 are provided for this purpose. However, we
cannot use it in  due to circular dependency
b/w .

In order to distangle it, we choose here to have a duplicate type,
netbsd32_siginfo_uint64, in . The equivalence
with netbsd32_uint64 is asserted in .

Now, gdb for i386 works again on amd64 kernel.

Based on patch provided by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.8 -r1.9 src/sys/compat/sys/siginfo.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32.h
diff -u src/sys/compat/netbsd32/netbsd32.h:1.130 src/sys/compat/netbsd32/netbsd32.h:1.131
--- src/sys/compat/netbsd32/netbsd32.h:1.130	Mon Nov 18 04:17:08 2019
+++ src/sys/compat/netbsd32/netbsd32.h	Mon Nov 18 12:06:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32.h,v 1.130 2019/11/18 04:17:08 rin Exp $	*/
+/*	$NetBSD: netbsd32.h,v 1.131 2019/11/18 12:06:26 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -162,6 +162,10 @@ typedef int64_t netbsd32_int64 NETBSD32_
 typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;
 #undef NETBSD32_INT64_ALIGN
 
+/* Type used in siginfo, avoids circular dependencies between headers. */
+CTASSERT(sizeof(netbsd32_uint64) == sizeof(netbsd32_siginfo_uint64));
+CTASSERT(__alignof__(netbsd32_uint64) == __alignof__(netbsd32_siginfo_uint64));
+
 /*
  * all pointers are netbsd32_pointer_t (defined in )
  */

Index: src/sys/compat/sys/siginfo.h
diff -u src/sys/compat/sys/siginfo.h:1.8 src/sys/compat/sys/siginfo.h:1.9
--- src/sys/compat/sys/siginfo.h:1.8	Mon Sep 30 21:13:33 2019
+++ src/sys/compat/sys/siginfo.h	Mon Nov 18 12:06:26 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: siginfo.h,v 1.8 2019/09/30 21:13:33 kamil Exp $	 */
+/*	$NetBSD: siginfo.h,v 1.9 2019/11/18 12:06:26 rin Exp $	 */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -34,6 +34,15 @@
 
 #ifdef _KERNEL
 
+/* Avoids circular dependency with machine/netbsd32_machdep.h */
+#if defined(__x86_64__) || (defined(__arm__) && defined(__ARM_EABI__))
+#define NETBSD32_SIGINFO_UINT64_ALIGN __attribute__((__aligned__(4)))
+#else
+#define NETBSD32_SIGINFO_UINT64_ALIGN __attribute__((__aligned__(8)))
+#endif
+typedef uint64_t netbsd32_siginfo_uint64 NETBSD32_SIGINFO_UINT64_ALIGN;
+#undef NETBSD32_SIGINFO_UINT64_ALIGN
+
 typedef union sigval32 {
 	int sival_int;
 	uint32_t sival_ptr;
@@ -73,7 +82,7 @@ struct __ksiginfo32 {
 			int	_sysnum;
 			int	_retval[2];
 			int	_error;
-			uint64_t _args[8]; /* SYS_MAXSYSARGS */
+			netbsd32_siginfo_uint64 _args[8]; /* SYS_MAXSYSARGS */
 		} _syscall;
 
 		struct {



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 11:01:41 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
TRAP_EXEC does not have extra fields to be filled in at the moment.
Explicitly ignore fields for now.

Pointed out by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 11:01:41 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
TRAP_EXEC does not have extra fields to be filled in at the moment.
Explicitly ignore fields for now.

Pointed out by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_signal.c
diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.49 src/sys/compat/netbsd32/netbsd32_signal.c:1.50
--- src/sys/compat/netbsd32/netbsd32_signal.c:1.49	Mon Nov 18 10:25:48 2019
+++ src/sys/compat/netbsd32/netbsd32_signal.c	Mon Nov 18 11:01:41 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_signal.c,v 1.49 2019/11/18 10:25:48 rin Exp $	*/
+/*	$NetBSD: netbsd32_signal.c,v 1.50 2019/11/18 11:01:41 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.49 2019/11/18 10:25:48 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.50 2019/11/18 11:01:41 rin Exp $");
 
 #if defined(_KERNEL_OPT) 
 #include "opt_ktrace.h"
@@ -213,6 +213,7 @@ fill_fault:
 	case SIGTRAP:
 		switch (si32->_code) {
 		case TRAP_EXEC:
+			break;
 		case TRAP_CHLD:
 		case TRAP_LWP:
 			si->_reason._ptrace_state._pe_report_event =
@@ -302,6 +303,7 @@ fill_fault:
 	case SIGTRAP:
 		switch (si->_code) {
 		case TRAP_EXEC:
+			break;
 		case TRAP_CHLD:
 		case TRAP_LWP:
 			si32->_reason._ptrace_state._pe_report_event =



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 10:25:48 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
When converting siginfo, examine si_code at the beginning,
as explained in siginfo(2).

- If it is SI_NOINFO, there's no additional information.
- If it is non-positive, i.e., codes described in siginfo(2),
  we need to fill in _rt.

XXX
Description for SA_ASYNCIO in siginfo(2) seems outdated;
neither si_fd nor si_band are filled in with that code.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_signal.c
diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.48 src/sys/compat/netbsd32/netbsd32_signal.c:1.49
--- src/sys/compat/netbsd32/netbsd32_signal.c:1.48	Mon Nov 18 10:14:52 2019
+++ src/sys/compat/netbsd32/netbsd32_signal.c	Mon Nov 18 10:25:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_signal.c,v 1.48 2019/11/18 10:14:52 rin Exp $	*/
+/*	$NetBSD: netbsd32_signal.c,v 1.49 2019/11/18 10:25:48 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.48 2019/11/18 10:14:52 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.49 2019/11/18 10:25:48 rin Exp $");
 
 #if defined(_KERNEL_OPT) 
 #include "opt_ktrace.h"
@@ -195,6 +195,11 @@ netbsd32_ksi32_to_ksi(struct _ksiginfo *
 	si->_code = si32->_code;
 	si->_errno = si32->_errno;
 
+	if (si32->_code == SI_NOINFO)
+		return;
+	else if (si32->_code <= 0)	/* codes described in siginfo(2) */
+		goto fill_rt;
+
 	switch (si32->_signo) {
 	case SIGILL:
 	case SIGFPE:
@@ -240,6 +245,7 @@ CTASSERT(sizeof(si->_reason._ptrace_stat
 	case SIGVTALRM:
 	case SIGPROF:
 	default:	/* see sigqueue() and kill1() */
+fill_rt:
 		si->_reason._rt._pid = si32->_reason._rt._pid;
 		si->_reason._rt._uid = si32->_reason._rt._uid;
 		si->_reason._rt._value.sival_int =
@@ -278,6 +284,11 @@ netbsd32_ksi_to_ksi32(struct __ksiginfo3
 	si32->_code = si->_code;
 	si32->_errno = si->_errno;
 
+	if (si->_code == SI_NOINFO)
+		return;
+	else if (si->_code <= 0)	/* codes described in siginfo(2) */
+		goto fill_rt;
+
 	switch (si->_signo) {
 	case SIGILL:
 	case SIGFPE:
@@ -323,6 +334,7 @@ CTASSERT(sizeof(si32->_reason._ptrace_st
 	case SIGVTALRM:
 	case SIGPROF:
 	default:	/* see sigqueue() and kill1() */
+fill_rt:
 		si32->_reason._rt._pid = si->_reason._rt._pid;
 		si32->_reason._rt._uid = si->_reason._rt._uid;
 		si32->_reason._rt._value.sival_int =



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 10:25:48 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
When converting siginfo, examine si_code at the beginning,
as explained in siginfo(2).

- If it is SI_NOINFO, there's no additional information.
- If it is non-positive, i.e., codes described in siginfo(2),
  we need to fill in _rt.

XXX
Description for SA_ASYNCIO in siginfo(2) seems outdated;
neither si_fd nor si_band are filled in with that code.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 10:14:52 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
Provide _ptrace_state for SIGTRAP with TRAP_EXEC, TRAP_CHLD, or TRAP_LWP.

Pointed out by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-18 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 10:14:52 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
Provide _ptrace_state for SIGTRAP with TRAP_EXEC, TRAP_CHLD, or TRAP_LWP.

Pointed out by kamil. Thanks!

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_signal.c
diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.47 src/sys/compat/netbsd32/netbsd32_signal.c:1.48
--- src/sys/compat/netbsd32/netbsd32_signal.c:1.47	Mon Nov 18 04:58:42 2019
+++ src/sys/compat/netbsd32/netbsd32_signal.c	Mon Nov 18 10:14:52 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_signal.c,v 1.47 2019/11/18 04:58:42 rin Exp $	*/
+/*	$NetBSD: netbsd32_signal.c,v 1.48 2019/11/18 10:14:52 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.47 2019/11/18 04:58:42 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.48 2019/11/18 10:14:52 rin Exp $");
 
 #if defined(_KERNEL_OPT) 
 #include "opt_ktrace.h"
@@ -206,17 +206,35 @@ fill_fault:
 		si->_reason._fault._trap = si32->_reason._fault._trap;
 		break;
 	case SIGTRAP:
-		if (si32->_code != TRAP_SCE && si32->_code != TRAP_SCX)
+		switch (si32->_code) {
+		case TRAP_EXEC:
+		case TRAP_CHLD:
+		case TRAP_LWP:
+			si->_reason._ptrace_state._pe_report_event =
+			si32->_reason._ptrace_state._pe_report_event;
+CTASSERT(sizeof(si->_reason._ptrace_state._option._pe_other_pid) ==
+sizeof(si->_reason._ptrace_state._option._pe_lwp));
+			si->_reason._ptrace_state._option._pe_other_pid =
+			si32->_reason._ptrace_state._option._pe_other_pid;
+			break;
+		case TRAP_SCE:
+		case TRAP_SCX:
+			si->_reason._syscall._sysnum =
+			si32->_reason._syscall._sysnum;
+			si->_reason._syscall._retval[0] =
+			si32->_reason._syscall._retval[0];
+			si->_reason._syscall._retval[1] =
+			si32->_reason._syscall._retval[1];
+			si->_reason._syscall._error =
+			si32->_reason._syscall._error;
+			for (i = 0;
+			i < __arraycount(si->_reason._syscall._args); i++)
+si->_reason._syscall._args[i] =
+si32->_reason._syscall._args[i];
+			break;
+		default:
 			goto fill_fault;
-		si->_reason._syscall._sysnum = si32->_reason._syscall._sysnum;
-		si->_reason._syscall._retval[0] =
-		si32->_reason._syscall._retval[0];
-		si->_reason._syscall._retval[1] =
-		si32->_reason._syscall._retval[1];
-		si->_reason._syscall._error = si32->_reason._syscall._error;
-		for (i = 0; i < __arraycount(si->_reason._syscall._args); i++)
-			si->_reason._syscall._args[i] =
-			si32->_reason._syscall._args[i];
+		}
 		break;
 	case SIGALRM:
 	case SIGVTALRM:
@@ -271,17 +289,35 @@ fill_fault:
 		si32->_reason._fault._trap = si->_reason._fault._trap;
 		break;
 	case SIGTRAP:
-		if (si->_code != TRAP_SCE && si->_code != TRAP_SCX)
+		switch (si->_code) {
+		case TRAP_EXEC:
+		case TRAP_CHLD:
+		case TRAP_LWP:
+			si32->_reason._ptrace_state._pe_report_event =
+			si->_reason._ptrace_state._pe_report_event;
+CTASSERT(sizeof(si32->_reason._ptrace_state._option._pe_other_pid) ==
+sizeof(si32->_reason._ptrace_state._option._pe_lwp));
+			si32->_reason._ptrace_state._option._pe_other_pid =
+			si->_reason._ptrace_state._option._pe_other_pid;
+			break;
+		case TRAP_SCE:
+		case TRAP_SCX:
+			si32->_reason._syscall._sysnum =
+			si->_reason._syscall._sysnum;
+			si32->_reason._syscall._retval[0] =
+			si->_reason._syscall._retval[0];
+			si32->_reason._syscall._retval[1] =
+			si->_reason._syscall._retval[1];
+			si32->_reason._syscall._error =
+			si->_reason._syscall._error;
+			for (i = 0;
+			i < __arraycount(si->_reason._syscall._args); i++)
+si32->_reason._syscall._args[i] =
+si->_reason._syscall._args[i];
+			break;
+		default:
 			goto fill_fault;
-		si32->_reason._syscall._sysnum = si->_reason._syscall._sysnum;
-		si32->_reason._syscall._retval[0] =
-		si->_reason._syscall._retval[0];
-		si32->_reason._syscall._retval[1] =
-		si->_reason._syscall._retval[1];
-		si32->_reason._syscall._error = si->_reason._syscall._error;
-		for (i = 0; i < __arraycount(si32->_reason._syscall._args); i++)
-			si32->_reason._syscall._args[i] =
-			si->_reason._syscall._args[i];
+		}
 		break;
 	case SIGALRM:
 	case SIGVTALRM:



CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:58:42 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
Sort by signal numbers as far as possible, adjust locations of functions.
No functional changes intended.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:58:42 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_signal.c

Log Message:
Sort by signal numbers as far as possible, adjust locations of functions.
No functional changes intended.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_signal.c
diff -u src/sys/compat/netbsd32/netbsd32_signal.c:1.46 src/sys/compat/netbsd32/netbsd32_signal.c:1.47
--- src/sys/compat/netbsd32/netbsd32_signal.c:1.46	Mon Nov 18 04:09:53 2019
+++ src/sys/compat/netbsd32/netbsd32_signal.c	Mon Nov 18 04:58:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_signal.c,v 1.46 2019/11/18 04:09:53 rin Exp $	*/
+/*	$NetBSD: netbsd32_signal.c,v 1.47 2019/11/18 04:58:42 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.46 2019/11/18 04:09:53 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_signal.c,v 1.47 2019/11/18 04:58:42 rin Exp $");
 
 #if defined(_KERNEL_OPT) 
 #include "opt_ktrace.h"
@@ -197,9 +197,9 @@ netbsd32_ksi32_to_ksi(struct _ksiginfo *
 
 	switch (si32->_signo) {
 	case SIGILL:
+	case SIGFPE:
 	case SIGBUS:
 	case SIGSEGV:
-	case SIGFPE:
 fill_fault:
 		si->_reason._fault._addr =
 		NETBSD32IPTR64(si32->_reason._fault._addr);
@@ -227,6 +227,11 @@ fill_fault:
 		si->_reason._rt._value.sival_int =
 		si32->_reason._rt._value.sival_int;
 		break;
+	case SIGURG:
+	case SIGIO:
+		si->_reason._poll._band = si32->_reason._poll._band;
+		si->_reason._poll._fd = si32->_reason._poll._fd;
+		break;
 	case SIGCHLD:
 		si->_reason._child._pid = si32->_reason._child._pid;
 		si->_reason._child._uid = si32->_reason._child._uid;
@@ -234,14 +239,17 @@ fill_fault:
 		si->_reason._child._utime = si32->_reason._child._utime;
 		si->_reason._child._stime = si32->_reason._child._stime;
 		break;
-	case SIGURG:
-	case SIGIO:
-		si->_reason._poll._band = si32->_reason._poll._band;
-		si->_reason._poll._fd = si32->_reason._poll._fd;
-		break;
 	}
 }
 
+void
+netbsd32_si32_to_si(siginfo_t *si, const siginfo32_t *si32)
+{
+
+	memset(si, 0, sizeof (*si));
+	netbsd32_ksi32_to_ksi(>_info, >_info);
+}
+
 static void
 netbsd32_ksi_to_ksi32(struct __ksiginfo32 *si32, const struct _ksiginfo *si)
 {
@@ -254,9 +262,9 @@ netbsd32_ksi_to_ksi32(struct __ksiginfo3
 
 	switch (si->_signo) {
 	case SIGILL:
+	case SIGFPE:
 	case SIGBUS:
 	case SIGSEGV:
-	case SIGFPE:
 fill_fault:
 		si32->_reason._fault._addr =
 		NETBSD32PTR32I(si->_reason._fault._addr);
@@ -284,6 +292,11 @@ fill_fault:
 		si32->_reason._rt._value.sival_int =
 		si->_reason._rt._value.sival_int;
 		break;
+	case SIGURG:
+	case SIGIO:
+		si32->_reason._poll._band = si->_reason._poll._band;
+		si32->_reason._poll._fd = si->_reason._poll._fd;
+		break;
 	case SIGCHLD:
 		si32->_reason._child._pid = si->_reason._child._pid;
 		si32->_reason._child._uid = si->_reason._child._uid;
@@ -291,11 +304,6 @@ fill_fault:
 		si32->_reason._child._utime = si->_reason._child._utime;
 		si32->_reason._child._stime = si->_reason._child._stime;
 		break;
-	case SIGURG:
-	case SIGIO:
-		si32->_reason._poll._band = si->_reason._poll._band;
-		si32->_reason._poll._fd = si->_reason._poll._fd;
-		break;
 	}
 }
 
@@ -308,14 +316,6 @@ netbsd32_si_to_si32(siginfo32_t *si32, c
 }
 
 void
-netbsd32_si32_to_si(siginfo_t *si, const siginfo32_t *si32)
-{
-
-	memset(si, 0, sizeof (*si));
-	netbsd32_ksi32_to_ksi(>_info, >_info);
-}
-
-void
 getucontext32(struct lwp *l, ucontext32_t *ucp)
 {
 	struct proc *p = l->l_proc;



CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:17:08 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h netbsd32_conv.h netbsd32_ioctl.c
netbsd32_ioctl.h

Log Message:
Sorry, revert unintentional parts of the previous commit:
http://mail-index.netbsd.org/source-changes/2019/11/18/msg110946.html

I was going to commit only netbsd32_signal.c.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.41 -r1.42 src/sys/compat/netbsd32/netbsd32_conv.h
cvs rdiff -u -r1.105 -r1.106 src/sys/compat/netbsd32/netbsd32_ioctl.c
cvs rdiff -u -r1.69 -r1.70 src/sys/compat/netbsd32/netbsd32_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32.h
diff -u src/sys/compat/netbsd32/netbsd32.h:1.129 src/sys/compat/netbsd32/netbsd32.h:1.130
--- src/sys/compat/netbsd32/netbsd32.h:1.129	Mon Nov 18 04:09:53 2019
+++ src/sys/compat/netbsd32/netbsd32.h	Mon Nov 18 04:17:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32.h,v 1.129 2019/11/18 04:09:53 rin Exp $	*/
+/*	$NetBSD: netbsd32.h,v 1.130 2019/11/18 04:17:08 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -37,7 +37,6 @@
  */
 
 #include  /* precautionary upon removal from ucred.h */
-#include 
 #include 
 #include 
 #include 
@@ -73,11 +72,7 @@ typedef int32_t netbsd32_key_t;
 typedef int32_t netbsd32_intptr_t;
 typedef uint32_t netbsd32_uintptr_t;
 
-/*
- * netbsd32_[u]int64 are machine dependent and defined in :
- * 64 bit integers only have 4-byte alignment on some 32 bit ports,
- * but always have 8-byte alignment on 64 bit systems.
- */
+/* netbsd32_[u]int64 are machine dependent and defined below */
 
 /*
  * machine dependant section; must define:
@@ -159,6 +154,15 @@ netbsd32_ptr32_incr(netbsd32_pointer_t *
 #undef NETBSD32_POINTER_TYPE
 
 /*
+ * 64 bit integers only have 4-byte alignment on some 32 bit ports,
+ * but always have 8-byte alignment on 64 bit systems.
+ * NETBSD32_INT64_ALIGN may be __attribute__((__aligned__(4)))
+ */
+typedef int64_t netbsd32_int64 NETBSD32_INT64_ALIGN;
+typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;
+#undef NETBSD32_INT64_ALIGN
+
+/*
  * all pointers are netbsd32_pointer_t (defined in )
  */
 
@@ -208,13 +212,14 @@ struct netbsd32_iovec {
 
 /* from  */
 typedef int32_t netbsd32_timer_t;
+typedef	int32_t netbsd32_time50_t;
 typedef	netbsd32_int64 netbsd32_time_t;
 typedef netbsd32_pointer_t netbsd32_timerp_t;
 typedef netbsd32_pointer_t netbsd32_clockidp_t;
 
 typedef netbsd32_pointer_t netbsd32_timespec50p_t;
 struct netbsd32_timespec50 {
-	int32_t		tv_sec;			/* seconds */
+	netbsd32_time50_t tv_sec;			/* seconds */
 	netbsd32_long	tv_nsec;	/* and nanoseconds */
 };
 
@@ -226,7 +231,7 @@ struct netbsd32_timespec {
 
 typedef netbsd32_pointer_t netbsd32_timeval50p_t;
 struct netbsd32_timeval50 {
-	netbsd32_long		tv_sec;		/* seconds */
+	netbsd32_time50_t	tv_sec;		/* seconds */
 	netbsd32_long		tv_usec;	/* and microseconds */
 };
 

Index: src/sys/compat/netbsd32/netbsd32_conv.h
diff -u src/sys/compat/netbsd32/netbsd32_conv.h:1.41 src/sys/compat/netbsd32/netbsd32_conv.h:1.42
--- src/sys/compat/netbsd32/netbsd32_conv.h:1.41	Mon Nov 18 04:09:53 2019
+++ src/sys/compat/netbsd32/netbsd32_conv.h	Mon Nov 18 04:17:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_conv.h,v 1.41 2019/11/18 04:09:53 rin Exp $	*/
+/*	$NetBSD: netbsd32_conv.h,v 1.42 2019/11/18 04:17:08 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -58,7 +58,7 @@ netbsd32_from_timeval50(const struct tim
 struct netbsd32_timeval50 *tv32)
 {
 
-	tv32->tv_sec = (netbsd32_long)tv->tv_sec;
+	tv32->tv_sec = (netbsd32_time50_t)tv->tv_sec;
 	tv32->tv_usec = (netbsd32_long)tv->tv_usec;
 }
 
@@ -152,7 +152,7 @@ netbsd32_from_timespec50(const struct ti
 struct netbsd32_timespec50 *s32p)
 {
 
-	s32p->tv_sec = (int32_t)p->tv_sec;
+	s32p->tv_sec = (netbsd32_time50_t)p->tv_sec;
 	s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
 }
 

Index: src/sys/compat/netbsd32/netbsd32_ioctl.c
diff -u src/sys/compat/netbsd32/netbsd32_ioctl.c:1.105 src/sys/compat/netbsd32/netbsd32_ioctl.c:1.106
--- src/sys/compat/netbsd32/netbsd32_ioctl.c:1.105	Mon Nov 18 04:09:53 2019
+++ src/sys/compat/netbsd32/netbsd32_ioctl.c	Mon Nov 18 04:17:08 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_ioctl.c,v 1.105 2019/11/18 04:09:53 rin Exp $	*/
+/*	$NetBSD: netbsd32_ioctl.c,v 1.106 2019/11/18 04:17:08 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.105 2019/11/18 04:09:53 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.106 2019/11/18 04:17:08 rin Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ntp.h"
@@ -1066,30 +1066,6 @@ netbsd32_do_clockctl_ntp_adjtime(struct 
 }
 #endif
 
-#ifdef COMPAT_50
-static void

CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:17:08 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h netbsd32_conv.h netbsd32_ioctl.c
netbsd32_ioctl.h

Log Message:
Sorry, revert unintentional parts of the previous commit:
http://mail-index.netbsd.org/source-changes/2019/11/18/msg110946.html

I was going to commit only netbsd32_signal.c.


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.41 -r1.42 src/sys/compat/netbsd32/netbsd32_conv.h
cvs rdiff -u -r1.105 -r1.106 src/sys/compat/netbsd32/netbsd32_ioctl.c
cvs rdiff -u -r1.69 -r1.70 src/sys/compat/netbsd32/netbsd32_ioctl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:09:53 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h netbsd32_conv.h netbsd32_ioctl.c
netbsd32_ioctl.h netbsd32_signal.c

Log Message:
Belatedly catch up with kern_sig.c rev 1.358:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/kern_sig.c#rev1.358

Provide syscall information with SIGTRAP TRAP_SCE/TRAP_SCX so that
picotrace/truss, for example, works fine on COMPAT_NETBSD32.

With some minor changes:

- Centralize netbsd32_si{,32}_si{32,}() into netbsd32_ksi{,32}_ksi{32,}().
- Provide si_status with SIGCHLD.
- Remove the remaining of SA.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.40 -r1.41 src/sys/compat/netbsd32/netbsd32_conv.h
cvs rdiff -u -r1.104 -r1.105 src/sys/compat/netbsd32/netbsd32_ioctl.c
cvs rdiff -u -r1.68 -r1.69 src/sys/compat/netbsd32/netbsd32_ioctl.h
cvs rdiff -u -r1.45 -r1.46 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-17 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov 18 04:09:53 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h netbsd32_conv.h netbsd32_ioctl.c
netbsd32_ioctl.h netbsd32_signal.c

Log Message:
Belatedly catch up with kern_sig.c rev 1.358:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/kern/kern_sig.c#rev1.358

Provide syscall information with SIGTRAP TRAP_SCE/TRAP_SCX so that
picotrace/truss, for example, works fine on COMPAT_NETBSD32.

With some minor changes:

- Centralize netbsd32_si{,32}_si{32,}() into netbsd32_ksi{,32}_ksi{32,}().
- Provide si_status with SIGCHLD.
- Remove the remaining of SA.

XXX
pullup to netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/compat/netbsd32/netbsd32.h
cvs rdiff -u -r1.40 -r1.41 src/sys/compat/netbsd32/netbsd32_conv.h
cvs rdiff -u -r1.104 -r1.105 src/sys/compat/netbsd32/netbsd32_ioctl.c
cvs rdiff -u -r1.68 -r1.69 src/sys/compat/netbsd32/netbsd32_ioctl.h
cvs rdiff -u -r1.45 -r1.46 src/sys/compat/netbsd32/netbsd32_signal.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32.h
diff -u src/sys/compat/netbsd32/netbsd32.h:1.128 src/sys/compat/netbsd32/netbsd32.h:1.129
--- src/sys/compat/netbsd32/netbsd32.h:1.128	Thu Nov  7 15:21:55 2019
+++ src/sys/compat/netbsd32/netbsd32.h	Mon Nov 18 04:09:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32.h,v 1.128 2019/11/07 15:21:55 rin Exp $	*/
+/*	$NetBSD: netbsd32.h,v 1.129 2019/11/18 04:09:53 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -37,6 +37,7 @@
  */
 
 #include  /* precautionary upon removal from ucred.h */
+#include 
 #include 
 #include 
 #include 
@@ -72,7 +73,11 @@ typedef int32_t netbsd32_key_t;
 typedef int32_t netbsd32_intptr_t;
 typedef uint32_t netbsd32_uintptr_t;
 
-/* netbsd32_[u]int64 are machine dependent and defined below */
+/*
+ * netbsd32_[u]int64 are machine dependent and defined in :
+ * 64 bit integers only have 4-byte alignment on some 32 bit ports,
+ * but always have 8-byte alignment on 64 bit systems.
+ */
 
 /*
  * machine dependant section; must define:
@@ -154,15 +159,6 @@ netbsd32_ptr32_incr(netbsd32_pointer_t *
 #undef NETBSD32_POINTER_TYPE
 
 /*
- * 64 bit integers only have 4-byte alignment on some 32 bit ports,
- * but always have 8-byte alignment on 64 bit systems.
- * NETBSD32_INT64_ALIGN may be __attribute__((__aligned__(4)))
- */
-typedef int64_t netbsd32_int64 NETBSD32_INT64_ALIGN;
-typedef uint64_t netbsd32_uint64 NETBSD32_INT64_ALIGN;
-#undef NETBSD32_INT64_ALIGN
-
-/*
  * all pointers are netbsd32_pointer_t (defined in )
  */
 
@@ -212,14 +208,13 @@ struct netbsd32_iovec {
 
 /* from  */
 typedef int32_t netbsd32_timer_t;
-typedef	int32_t netbsd32_time50_t;
 typedef	netbsd32_int64 netbsd32_time_t;
 typedef netbsd32_pointer_t netbsd32_timerp_t;
 typedef netbsd32_pointer_t netbsd32_clockidp_t;
 
 typedef netbsd32_pointer_t netbsd32_timespec50p_t;
 struct netbsd32_timespec50 {
-	netbsd32_time50_t tv_sec;			/* seconds */
+	int32_t		tv_sec;			/* seconds */
 	netbsd32_long	tv_nsec;	/* and nanoseconds */
 };
 
@@ -231,7 +226,7 @@ struct netbsd32_timespec {
 
 typedef netbsd32_pointer_t netbsd32_timeval50p_t;
 struct netbsd32_timeval50 {
-	netbsd32_time50_t	tv_sec;		/* seconds */
+	netbsd32_long		tv_sec;		/* seconds */
 	netbsd32_long		tv_usec;	/* and microseconds */
 };
 

Index: src/sys/compat/netbsd32/netbsd32_conv.h
diff -u src/sys/compat/netbsd32/netbsd32_conv.h:1.40 src/sys/compat/netbsd32/netbsd32_conv.h:1.41
--- src/sys/compat/netbsd32/netbsd32_conv.h:1.40	Thu Oct  3 22:16:53 2019
+++ src/sys/compat/netbsd32/netbsd32_conv.h	Mon Nov 18 04:09:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_conv.h,v 1.40 2019/10/03 22:16:53 kamil Exp $	*/
+/*	$NetBSD: netbsd32_conv.h,v 1.41 2019/11/18 04:09:53 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -58,7 +58,7 @@ netbsd32_from_timeval50(const struct tim
 struct netbsd32_timeval50 *tv32)
 {
 
-	tv32->tv_sec = (netbsd32_time50_t)tv->tv_sec;
+	tv32->tv_sec = (netbsd32_long)tv->tv_sec;
 	tv32->tv_usec = (netbsd32_long)tv->tv_usec;
 }
 
@@ -152,7 +152,7 @@ netbsd32_from_timespec50(const struct ti
 struct netbsd32_timespec50 *s32p)
 {
 
-	s32p->tv_sec = (netbsd32_time50_t)p->tv_sec;
+	s32p->tv_sec = (int32_t)p->tv_sec;
 	s32p->tv_nsec = (netbsd32_long)p->tv_nsec;
 }
 

Index: src/sys/compat/netbsd32/netbsd32_ioctl.c
diff -u src/sys/compat/netbsd32/netbsd32_ioctl.c:1.104 src/sys/compat/netbsd32/netbsd32_ioctl.c:1.105
--- src/sys/compat/netbsd32/netbsd32_ioctl.c:1.104	Tue Aug 20 09:32:21 2019
+++ src/sys/compat/netbsd32/netbsd32_ioctl.c	Mon Nov 18 04:09:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32_ioctl.c,v 1.104 2019/08/20 09:32:21 christos Exp $	*/
+/*	$NetBSD: netbsd32_ioctl.c,v 1.105 2019/11/18 04:09:53 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -31,7 +31,7 @@
  */
 
 #include 

CVS commit: src/sys/kern

2019-11-16 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 17 02:22:14 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Fix pointer arithmetic for 32-bit process on LP64 kernel in
process_auxv_offset().

Now, PIOD_READ_AUXV works fine with COMPAT_NETBSD32.

XXX
pullup to netbsd-9 and netbsd-8


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/kern

2019-11-16 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Nov 17 02:22:14 UTC 2019

Modified Files:
src/sys/kern: sys_ptrace_common.c

Log Message:
Fix pointer arithmetic for 32-bit process on LP64 kernel in
process_auxv_offset().

Now, PIOD_READ_AUXV works fine with COMPAT_NETBSD32.

XXX
pullup to netbsd-9 and netbsd-8


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/kern/sys_ptrace_common.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/sys_ptrace_common.c
diff -u src/sys/kern/sys_ptrace_common.c:1.71 src/sys/kern/sys_ptrace_common.c:1.72
--- src/sys/kern/sys_ptrace_common.c:1.71	Wed Nov 13 15:48:36 2019
+++ src/sys/kern/sys_ptrace_common.c	Sun Nov 17 02:22:14 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_ptrace_common.c,v 1.71 2019/11/13 15:48:36 pgoyette Exp $	*/
+/*	$NetBSD: sys_ptrace_common.c,v 1.72 2019/11/17 02:22:14 rin Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.71 2019/11/13 15:48:36 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_ptrace_common.c,v 1.72 2019/11/17 02:22:14 rin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ptrace.h"
@@ -1635,7 +1635,15 @@ process_auxv_offset(struct proc *p, stru
 	if (pss.ps_envstr == NULL)
 		return EIO;
 
-	uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr + pss.ps_nenvstr + 1);
+#ifdef COMPAT_NETBSD32
+	if (p->p_flag & PK_32)
+		uio->uio_offset += (off_t)((vaddr_t)pss.ps_envstr +
+		sizeof(uint32_t) * (pss.ps_nenvstr + 1));
+	else
+#endif
+		uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr +
+		pss.ps_nenvstr + 1);
+
 #ifdef __MACHINE_STACK_GROWS_UP
 	if (uio->uio_offset < off)
 		return EIO;



CVS commit: src/sys/compat/netbsd32

2019-11-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Nov  7 15:21:56 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h

Log Message:
For netbsd32_statvfs, f_spare should be netbsd32_uint64, not uint64_t.

Fix syscalls using struct statvfs on COMPAT_NETBSD32 on amd64, where
NETBSD32_INT64_ALIGN is __attribute__((__aligned__(4))).


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/compat/netbsd32/netbsd32.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Nov  7 15:21:56 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32.h

Log Message:
For netbsd32_statvfs, f_spare should be netbsd32_uint64, not uint64_t.

Fix syscalls using struct statvfs on COMPAT_NETBSD32 on amd64, where
NETBSD32_INT64_ALIGN is __attribute__((__aligned__(4))).


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/sys/compat/netbsd32/netbsd32.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32.h
diff -u src/sys/compat/netbsd32/netbsd32.h:1.127 src/sys/compat/netbsd32/netbsd32.h:1.128
--- src/sys/compat/netbsd32/netbsd32.h:1.127	Thu Oct  3 22:16:53 2019
+++ src/sys/compat/netbsd32/netbsd32.h	Thu Nov  7 15:21:55 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: netbsd32.h,v 1.127 2019/10/03 22:16:53 kamil Exp $	*/
+/*	$NetBSD: netbsd32.h,v 1.128 2019/11/07 15:21:55 rin Exp $	*/
 
 /*
  * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
@@ -902,7 +902,7 @@ struct netbsd32_statvfs {
 	netbsd32_u_long	f_fsid;		/* Posix compatible fsid */
 	netbsd32_u_long	f_namemax;	/* maximum filename length */
 	uid_t		f_owner;	/* user that mounted the file system */
-	uint64_t	f_spare[4];	/* spare space */
+	netbsd32_uint64	f_spare[4];	/* spare space */
 	char	f_fstypename[_VFS_NAMELEN]; /* fs type name */
 	char	f_mntonname[_VFS_MNAMELEN];  /* directory on which mounted */
 	char	f_mntfromname[_VFS_MNAMELEN];  /* mounted file system */



Re: CVS commit: src/sys/compat/netbsd32

2019-11-04 Thread Rin Okuyama

On 2019/11/04 20:20, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Mon Nov  4 11:20:22 UTC 2019

Modified Files:
src/sys/compat/netbsd32: syscalls.master

Log Message:
For netbsd32_readlinkat(2), bufsize is netbsd_size_t, not size_t.
Since bufsize is the last argument, this affects only LP64EB.

XXX
pullup to netbsd-9, -8, and -7


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sys/compat/netbsd32/syscalls.master

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


s/netbsd_size_t/netbsd32_size_t/ in the commit log.


CVS commit: src/sys/compat/netbsd32

2019-11-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  4 11:33:01 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_syscall.h netbsd32_syscallargs.h
netbsd32_syscalls.c netbsd32_syscalls_autoload.c netbsd32_sysent.c
netbsd32_systrace_args.c

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/compat/netbsd32/netbsd32_syscall.h
cvs rdiff -u -r1.144 -r1.145 src/sys/compat/netbsd32/netbsd32_syscallargs.h \
src/sys/compat/netbsd32/netbsd32_syscalls.c
cvs rdiff -u -r1.24 -r1.25 \
src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c
cvs rdiff -u -r1.143 -r1.144 src/sys/compat/netbsd32/netbsd32_sysent.c
cvs rdiff -u -r1.35 -r1.36 src/sys/compat/netbsd32/netbsd32_systrace_args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/compat/netbsd32

2019-11-04 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Nov  4 11:33:01 UTC 2019

Modified Files:
src/sys/compat/netbsd32: netbsd32_syscall.h netbsd32_syscallargs.h
netbsd32_syscalls.c netbsd32_syscalls_autoload.c netbsd32_sysent.c
netbsd32_systrace_args.c

Log Message:
regen


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/sys/compat/netbsd32/netbsd32_syscall.h
cvs rdiff -u -r1.144 -r1.145 src/sys/compat/netbsd32/netbsd32_syscallargs.h \
src/sys/compat/netbsd32/netbsd32_syscalls.c
cvs rdiff -u -r1.24 -r1.25 \
src/sys/compat/netbsd32/netbsd32_syscalls_autoload.c
cvs rdiff -u -r1.143 -r1.144 src/sys/compat/netbsd32/netbsd32_sysent.c
cvs rdiff -u -r1.35 -r1.36 src/sys/compat/netbsd32/netbsd32_systrace_args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/netbsd32/netbsd32_syscall.h
diff -u src/sys/compat/netbsd32/netbsd32_syscall.h:1.145 src/sys/compat/netbsd32/netbsd32_syscall.h:1.146
--- src/sys/compat/netbsd32/netbsd32_syscall.h:1.145	Mon Nov  4 11:21:36 2019
+++ src/sys/compat/netbsd32/netbsd32_syscall.h	Mon Nov  4 11:33:01 2019
@@ -1,10 +1,10 @@
-/* $NetBSD: netbsd32_syscall.h,v 1.145 2019/11/04 11:21:36 rin Exp $ */
+/* $NetBSD: netbsd32_syscall.h,v 1.146 2019/11/04 11:33:01 rin Exp $ */
 
 /*
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.129 2019/11/04 11:20:22 rin Exp
+ * created from	NetBSD: syscalls.master,v 1.130 2019/11/04 11:32:22 rin Exp
  */
 
 #ifndef _NETBSD32_SYS_SYSCALL_H_
@@ -1274,7 +1274,7 @@
 /* syscall: "netbsd32_clock_getcpuclockid2" ret: "int" args: "idtype_t" "id_t" "netbsd32_clockidp_t" */
 #define	NETBSD32_SYS_netbsd32_clock_getcpuclockid2	482
 
-/* syscall: "netbsd32___getvfsstat90" ret: "int" args: "netbsd32_statvfsp_t" "size_t" "int" */
+/* syscall: "netbsd32___getvfsstat90" ret: "int" args: "netbsd32_statvfsp_t" "netbsd32_size_t" "int" */
 #define	NETBSD32_SYS_netbsd32___getvfsstat90	483
 
 /* syscall: "netbsd32___statvfs190" ret: "int" args: "netbsd32_charp" "netbsd32_statvfsp_t" "int" */
@@ -1283,7 +1283,7 @@
 /* syscall: "netbsd32___fstatvfs190" ret: "int" args: "int" "netbsd32_statvfsp_t" "int" */
 #define	NETBSD32_SYS_netbsd32___fstatvfs190	485
 
-/* syscall: "netbsd32___fhstatvfs190" ret: "int" args: "netbsd32_voidp" "size_t" "netbsd32_statvfsp_t" "int" */
+/* syscall: "netbsd32___fhstatvfs190" ret: "int" args: "netbsd32_voidp" "netbsd32_size_t" "netbsd32_statvfsp_t" "int" */
 #define	NETBSD32_SYS_netbsd32___fhstatvfs190	486
 
 #define	NETBSD32_SYS_MAXSYSCALL	487

Index: src/sys/compat/netbsd32/netbsd32_syscallargs.h
diff -u src/sys/compat/netbsd32/netbsd32_syscallargs.h:1.144 src/sys/compat/netbsd32/netbsd32_syscallargs.h:1.145
--- src/sys/compat/netbsd32/netbsd32_syscallargs.h:1.144	Mon Nov  4 11:21:36 2019
+++ src/sys/compat/netbsd32/netbsd32_syscallargs.h	Mon Nov  4 11:33:01 2019
@@ -1,10 +1,10 @@
-/* $NetBSD: netbsd32_syscallargs.h,v 1.144 2019/11/04 11:21:36 rin Exp $ */
+/* $NetBSD: netbsd32_syscallargs.h,v 1.145 2019/11/04 11:33:01 rin Exp $ */
 
 /*
  * System call argument lists.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.129 2019/11/04 11:20:22 rin Exp
+ * created from	NetBSD: syscalls.master,v 1.130 2019/11/04 11:32:22 rin Exp
  */
 
 #ifndef _NETBSD32_SYS_SYSCALLARGS_H_
@@ -2624,7 +2624,7 @@ check_syscall_args(netbsd32_clock_getcpu
 
 struct netbsd32___getvfsstat90_args {
 	syscallarg(netbsd32_statvfsp_t) buf;
-	syscallarg(size_t) bufsize;
+	syscallarg(netbsd32_size_t) bufsize;
 	syscallarg(int) flags;
 };
 check_syscall_args(netbsd32___getvfsstat90)
@@ -2645,7 +2645,7 @@ check_syscall_args(netbsd32___fstatvfs19
 
 struct netbsd32___fhstatvfs190_args {
 	syscallarg(netbsd32_voidp) fhp;
-	syscallarg(size_t) fh_size;
+	syscallarg(netbsd32_size_t) fh_size;
 	syscallarg(netbsd32_statvfsp_t) buf;
 	syscallarg(int) flags;
 };
Index: src/sys/compat/netbsd32/netbsd32_syscalls.c
diff -u src/sys/compat/netbsd32/netbsd32_syscalls.c:1.144 src/sys/compat/netbsd32/netbsd32_syscalls.c:1.145
--- src/sys/compat/netbsd32/netbsd32_syscalls.c:1.144	Mon Nov  4 11:21:36 2019
+++ src/sys/compat/netbsd32/netbsd32_syscalls.c	Mon Nov  4 11:33:01 2019
@@ -1,14 +1,14 @@
-/* $NetBSD: netbsd32_syscalls.c,v 1.144 2019/11/04 11:21:36 rin Exp $ */
+/* $NetBSD: netbsd32_syscalls.c,v 1.145 2019/11/04 11:33:01 rin Exp $ */
 
 /*
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.129 2019/11/04 11:20:22 rin Exp
+ * created from	NetBSD: syscalls.master,v 1.130 2019/11/04 11:32:22 rin Exp
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls.c,v 1.144 2019/11/04 11:21:36 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_syscalls.c,v 1.145 2019/11/04 11:33:01 rin Exp $");
 
 #if defined(_KERNEL_OPT)

  1   2   3   4   5   >