Code Monkey home page Code Monkey logo

libnx's Introduction

Nintendo Switch AArch64-only userland library.

Based on libctru.

Build status

Install instructions

See Switchbrew.

libnx's People

Contributors

adubbz avatar andoma avatar averne avatar cpasjuste avatar crossvr avatar ctcaer avatar darkmattercore avatar endrift avatar fincs avatar german77 avatar hexkyz avatar hookedbehemoth avatar joel16 avatar liamwhite avatar lioncash avatar masagrator avatar mtheall avatar natinusala avatar ndeadly avatar p-sam avatar plutooo avatar rajkosto avatar sciresm avatar shchmue avatar shinyquagsire23 avatar stary2001 avatar tuxsh avatar wintermute avatar xortroll avatar yellows8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libnx's Issues

Any support for bluetooth operations?

Hey there,
I was looking around and can't find anything related to the bluetooth stack. Is it possible to support bluetooth operations at this layer?

I'm guessing if it was it would probably be in here already, but I figured I'd at least ask about it. I'd love to develop a way to allow wii u pro controllers to pair with the switch bluetooth controller.

Graphics crashes on firmware 1.0

It seems libnx has some issues with graphics on firmware 1.0. Many programs such as nx-hbmenu and FTPd seem to crash with 2345-0021. If I've read the libnx error list correctly, this is "LibnxError_BadGfxDequeueBuffer".

To reproduce this, simply run nx-hbmenu as normal on firmware 1.0, then wait for it (or any applications you launch from it) to crash; this often occurs immediately on launch, but can take a few seconds to a few minutes on occasion.

Thank you.

APP_TITLEID is ignored in Makefile

The APP_TITLEID tag is ignored in makefile (libnx 1.5.0 in devkitPro). Instead of putting the specified tittleid in the nacp file, there is still the standard (00000000ffffffff) titleid.

This is how I specified my titleid in makefile:
APP_TITLEID = 0100000000000002

FIY: APP_TITLE, APP_AUTHOR and APP_VERSION are working correctly.

Problem with getting networking to work, using ifr_flags

I am not sure if this is really an issue, or if I am just missing something.

The app I am working on currently (OpenTTD port) does this in the networking code:

if (r.ifr_flags & IFF_BROADCAST) continue;

Which according to every page I found about inet and net.h and whatever should be valid.

However, libnx declares ifr_flags as short int[2]:

short ifr_flags[2]; /* flags (low 16 bits) */

but defines IFF_BROADCAST as 0x02. So the check for the flag gives a compile error because I am trying to do a binary and operation on two different types (short int[2] and int).

I have two questions, the second one being the only pressing one atm:
a) Why is ifr_flags declared as short int[2], not short int, like it is done in every linux on the planet?
See e.g. http://man7.org/linux/man-pages/man7/netdevice.7.html

b) How do I fix the code to continue when the IFF_BROADCAST flag is set? Is it ok to cast like this if ((*((int *)(r.ifr_flags))) & IFF_BROADCAST) continue? This looks extremely ugly and I suspect it won't do what I want.

I simply don't understand which bit in the array of two shorts I should check for.

Audio output broken on firmware 1.0.0 [audout]

Audio output does not work on 1.0.0. I tested with all of the audio examples from switch-examples, playing an MP3 with NX-Shell, and playing a game with mGBA and all of them were completely silent; I tested with NROs compiled with the latest libnx. Here is the output from the audio switch-examples:

I believe the return result in audren-simple.nro may be the problem, as 0x499 is the Invalid buffer address failure case. It seems a similar issue may have been fixed in the past but audio output remains broken.

I can't compile tools

OS: Win 10
These messages show up when I try to compile elf2nso
cmd
Where can I find those files?

Socket crash

If around 398MB of heap data got allocated after initializing the socket service using socketInitializeDefault() and then either socketExit() got called or the homebrew exits and tries to return to the hbmenu, the Switch crashes with an error code of 2168-0002 (Segmentation Fault).

Here's the source code of a PoC homebrew app to demonstrate the issue: https://gist.github.com/WerWolv98/2f57359e72634e33be7d64a07009aa35

It's using libnx version 1.3.2. The issue was NOT present on earlier versions (prior to 1.3.0)

Libnx 2.0.0 slower graphics than older version

I updated libnx (and all other dkp-pacman packages) from previous stable version to 2.0.0. I re-compiled uae4all2. I am now getting more graphics stutters during scrolling than before. I double-checked by direct comparison between versions compiled with older libnx and 2.0.0.

The app uses SDL2 which used EGL. Has anything changed in 2.0.0 in the way vsync is done, or frames are drawn, or gfx is initialized, or anything else maybe timing or graphics related that could cause increased frame drops and stuttering during scrolling?

Maybe Vsync is now disabled by default? And it was enabled before?

HidKeysHeld() behaviur

Upons subsequent hidScanInput(), with a key mantained pressed, HidKeysHeld() seems to change state (key pressed -> key not pressed -> key pressed -> ...) instead to remain steady.

Attached a simple test code. The behaviour happens on RyujiNX (I don't have a real Switch to test it) and I thought it vas an issue of the emulater, but some user reported it happens on real hw too.
testkeys2.zip

Simulate press button

Is there a function or something that for example press button A, without touching the button physically?

Fail to build

latest devkitA64, WSL (Ubuntu 16.04)

/home/wl/libnx/nx/source/runtime/newlib.c: In function 'newlibSetup':
/home/wl/libnx/nx/source/runtime/newlib.c:130:15: error: '__syscalls_t {aka struct <anonymous>}' has no member named 'nanosleep'
     __syscalls.nanosleep = __libnx_nanosleep;

Makefile errors without exefs_src directory

If I do the following to build the simple example:

git clone https://github.com/switchbrew/switch-examples
cd ~/switch-examples/templates/simple
make``

Results in the following error:

linking simple.elf
built ... simple.nso
cp: cannot stat '/home/user/switch-examples/templates/simple/exefs_src/*': No such file or directory
/home/user/devkitpro/devkitA64/switch_rules:13: recipe for target '/home/user/switch-examples/templates/simple/simple.pfs0' failed
make[1]: *** [/home/user/switch-examples/templates/simple/simple.pfs0] Error 1
Makefile:103: recipe for target 'build' failed
make: *** [build] Error 2

I can get around it by making an empty folder inside of exefs_src, and then trying to compile:

cd ~/switch-examples/templates/simple
mkdir -p exefs_src/a
make

Results in:

linking simple.elf
built ... simple.nso
Directories aren't supported, skipping... (exefs/a)
built ... simple.pfs0

Should libnx still proceed even when the exefs_src directory doesn't exist or is empty?

Conversion errors in ipc.h

I was using libnx to compile a test executable for the Switch (thanks for this, by the way!), when I ran into some errors related to invalid conversions in ipc.h while compiling. Here's the error:

aarch64-none-elf-g++ -o C:/Users/mason/source/repos/Switch/Switch/Build/Main.out -LC:/devkitPro/libnx/lib -IC:/devkitPro/libnx/include -lnx -static -static-libgcc -static-libstdc++ Main.cpp <

In file included from C:/devkitPro/libnx/include/switch.h:15:0,
                 from Main.cpp:3:
C:/devkitPro/libnx/include/switch/ipc.h: In function 'void* ipcPrepareHeader(IpcCommand*, size_t)':
C:/devkitPro/libnx/include/switch/ipc.h:109:25: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissive]
     u32* buf = armGetTls();
                ~~~~~~~~~^~
C:/devkitPro/libnx/include/switch/ipc.h: In function 'Result ipcParseResponse(IpcCommandResponse*)':
C:/devkitPro/libnx/include/switch/ipc.h:209:25: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissive]
     u32* buf = armGetTls();
                ~~~~~~~~~^~
C:/devkitPro/libnx/include/switch/ipc.h: In function 'Result ipcQueryPointerBufferSize(Handle, size_t*)':
C:/devkitPro/libnx/include/switch/ipc.h:262:25: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissive]
     u32* buf = armGetTls();
                ~~~~~~~~~^~
C:/devkitPro/libnx/include/switch/ipc.h:283:20: error: invalid conversion from 'void*' to 'ipcQueryPointerBufferSize(Handle, size_t*)::<unnamed struct>*' [-fpermissive]
         } *raw = r.Raw;
                  ~~^~~
C:/devkitPro/libnx/include/switch/ipc.h: In function 'Result ipcConvertSessionToDomain(Handle, u32*)':
C:/devkitPro/libnx/include/switch/ipc.h:297:25: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissive]
     u32* buf = armGetTls();
                ~~~~~~~~~^~
C:/devkitPro/libnx/include/switch/ipc.h:316:20: error: invalid conversion from 'void*' to 'ipcConvertSessionToDomain(Handle, u32*)::<unnamed struct>*' [-fpermissive]
         } *raw = r.Raw;
                  ~~^~~

I seemed to fix these errors by casting armGetTls() to (u32*) in each occurrance, and by naming the mentioned structs "raw" and casting r.Raw to (struct raw *). Here are the lines:

Lines 109, 209, 262, 297:

u32* buf = (u32*) armGetTls();

Lines 279-283, 312-316:

struct raw {
    u64 magic;
    u64 result;
    u32 object_id;
} *raw = (struct raw *) r.Raw;

Feel free to change these, I'm kind of a novice at C/C++, so there might be some unintended consequences haha.

Keep up the great work!

Compiler warning after simply #including <switch.h>

Using my own Makefile with some required modifications for switch, and here's the problem:
including <switch.h> includes "switch/services/audren.h", which has line
"#if __cplusplus >= 201402L". __cplusplus is completely undefined in my C code.

That becomes a warning (which becomes build breaking error, with any sensible build switches)

Perhaps there should be #ifdef __cplusplus around it?

when trying to use crop on horizontal resolution, switch crashes

hello

with the following code, i am able to create a crop at the top of the screen, so that the first 12 lines are not displayed :

    gfxConfigureCrop(0, 12, 0, 0); 
    gfxInitResolution(1280, 732);
    gfxConfigureResolution(1280,720);
    gfxInitDefault();

checking for resolution, i get 1280*732

but when using this , to have an horizontal crop :

    gfxConfigureCrop(32, 12, 0, 0); 
    gfxInitResolution(1280+32, 732);
    gfxConfigureResolution(1280,720);
    gfxInitDefault();

i get a crash with error 2345-0018

am i missing a point ? or is it a bug ?

thanks

my switch is 3.0.0, running HBL through pegaswitch

scandir implementation issue.

I not properly know where to report this issue.
Right now I can't use provided scandir implementation.
So I use such code snippet for this:

#define INITIAL_ALLOCATION 20

static int static_scandir(const char *directory_name, struct dirent ***array_pointer,
              int (*select_function)(const struct dirent *),
               int (*compare_function) (const struct dirent **, const struct dirent **)) {
   DIR *directory;
    struct dirent **array;
    struct dirent *entry;
    struct dirent *copy;
    int allocated = INITIAL_ALLOCATION;
    int counter = 0;

    /* Get initial list space and open directory.  */

    if (directory = opendir(directory_name), directory == NULL)
        return -1;

    if ((array = (struct dirent **)malloc(allocated * sizeof(struct dirent *))) == NULL)
        return -1;

    /* Read entries in the directory.  */

    while (entry = readdir(directory), entry)
        if (select_function == NULL || (*select_function) (entry)) {
            /* User wants them all, or he wants this one.  Copy the entry.  */

           
            int namelength = strlen(entry->d_name) + 1; /* length with NULL */
            int extra = 0;

            if (sizeof(entry->d_name) <= namelength) {
                /* allocated space <= required space */
                extra += namelength - sizeof(entry->d_name);
            }

            if ((copy = (struct dirent *)malloc(sizeof(struct dirent) + extra)) == NULL) {
                closedir(directory);
                free(array);
                return -1;
            }
            copy->d_ino = entry->d_ino;
            copy->d_type = entry->d_type;
            strcpy(copy->d_name, entry->d_name);

            /* Save the copy.  */

            if (counter + 1 == allocated) {
                allocated <<= 1;
                array = (struct dirent **)
                    reallocf((char *)array, allocated * sizeof(struct dirent *));
                if (array == NULL) {
                    closedir(directory);
                    free(array);
                    free(copy);
                    return -1;
                }
            }
            array[counter++] = copy;
        }

    /* Close things off.  */

    array[counter] = NULL;
    *array_pointer = array;
    closedir(directory);

    /* Sort?  */

    if (counter > 1 && compare_function)
        qsort((char *)array, counter, sizeof(struct dirent *)
              , (int (*)(const void *, const void *))(compare_function));

    return counter;
} 

Maybe you could adopt this code, or any other open source implementation.

USB bind error

Hi. I'm developing debugger client that communicates with nxdbg stub app through USB connection.
But stub app can't initialize usb connection due to error code 0xf601(i.e port remote dead)
in this line.

My debugger client opens USB connection correctly(right vendor id, endpoint...).
What's the problem? Have you encountered such error code?

ipc: extra alignment bytes at the end of request rawdata

This pattern used all over the library include extraneous padding bytes at the end of the rawdata, since sizeof(struct) is padded up to match the stride address. In this case, sizeof(*raw) is u64 magic + u64 cmd_id + u32 flags + u32 padding = 16 bytes instead of the correct 12 bytes. Official server code permits extra rawdata, but I don't think official client code includes this padding.

struct {
u64 magic;
u64 cmd_id;
u32 flags;
} *raw;
raw = serviceIpcPrepareHeader(&fs->s, &c, sizeof(*raw));

License?

What license are you planning on releasing this under?

Missing exception handle in version distributed via pacman

Version of library distributed by pacman is different from version in master branch.

Some of missing stuff found:

  • ThreadExceptionDump and ThreadExceptionDesc are missing in /opt/devkit/include/switch/arm/thread_context.h
  • exception handling is missing in examples

sudo dkp-pacman -Syu doesn't solve the issue

Problems with single Joycon (cannot read KEY_SR, KEY_SL, etc.)

I either stumbled across some bugs regarding single Joycon support in libnx, or I just don't understand it.

I am seeking a way to switch to single (split) joycons mode with

  • automatic stick axes/button rotation for horizontal mode
  • an ability to read out KEY_SR and KEY_SL.

I can succesfully switch joycons to single "vertical" mode via hidSetNpadJoyAssignmentModeSingleByDefault((HidControllerID) id).

It works, but it is not really the mode I want. On left controllers, this reassigns udlr to xyab. On right controllers, RStick_xxx is re-assigned to LStick_xxx, as expected. One of the problems is that in this mode it doesn't rotate the inputs. I have to manually re-assign all the buttons and stick axes for horizontal handling.

In addition, I cannot read out KEY_SR, KEY_SL in this mode, there's just no input from those. This is a dealbreaker at the moment. All other keys work using my code, even L and ZL on the side of the horizontal controller, apart from KEY_SR or KEY_SL. I just never get any input from KEY_SR or KEY_SL.

Is there maybe another command I have to use to switch to horizontal mode to make axes and button rotation and KEY_SR and KEY_SL work?
I tried hidSetControllerLayout((HidControllerID) id, LAYOUT_SINGLE); but when I use it, all input from the controller I switch to LAYOUT_SINGLE is muted.

I saw there's a function hidSetNpadJoyHoldType(u64 type) with no documentation. Is this what I have to use to switch to horizontal mode? What are the parameters?

Here's some example code:

for (int id=0; id<8; id++) {
  hidSetNpadJoyAssignmentModeSingleByDefault((HidControllerID) id);
}
// switching the layout to LAYOUT_SINGLE seems broken: no inputs are registered on the controller anymore as soon as I switch to LAYOUT_SINGLE)
//for (int id=0; id<8; id++) {
//  hidSetControllerLayout((HidControllerID) id, LAYOUT_SINGLE);
//}

//SL and SR are never registered for some unknown reason
// all other buttons work using this code, just not KEY_SL or KEY_SR
u64 single_joycon_buttons = hidKeysHeld((HidControllerID) 0);
if (single_joycon_buttons & KEY_SL)
  //"printf("SL pressed")"

Lack of Japanese Character Support

All the homebrew I have tried that uses libnx has issues with reading files with Japanese characters off the sd card. As far as I can tell the issue stems from lack of non ASCII FS support on libnx.

MOD0 section missing an offset

right now the mod0 section looks like this in switch_crt0.s

.global __nx_mod0
__nx_mod0:
    .ascii "MOD0"
    .word  _DYNAMIC             - __nx_mod0
    .word  __bss_start__        - __nx_mod0
    .word  __bss_end__          - __nx_mod0
    .word  __eh_frame_hdr_start - __nx_mod0
    .word  __eh_frame_hdr_end   - __nx_mod0
    .word  0 // "offset to runtime-generated module object" (??)

since the last part (offset to runtime-generated module object) is missing, official rtld crashes when trying to load a homebrew nso. switchbrew says it's "typically equal to .bss base", so i just copied the bss start offset value into it and the game fine booted with a homebrew nso loaded. of course, this probably causes some issues (i haven't tried actually executing code in the nso yet), but it might be helpful for figuring out what this offset is actually for. it's also worth noting that i noticed that the bss start offset and the runtime-generated module object offset have the same value in official nsos, too

about audoutGetReleasedAudioOutBuffer

Hello

i don't know if it is an issue but i tried the following things :

  • create 2 buffers of type AudioOutBuffer
  • initialize them and append them to the audio buffer
  • start the audio system
  • the 2 buffers play well ( no crash, sound seems ok )
  • use audoutGetReleasedAudioOutBuffer
  • the buffer coming from audoutGetReleasedAudioOutBuffer is not any of the 2 buffers i append before
  • the released buffer is not filled with right values, or any values i setup ( size, pointer to memory buffer for sample and so on )

i thought that the logic of this audio system was : i append a buffer, the audio system uses it, and when i call getreleasedaudio , i get back a buffer i did append before ?

vibration does not work

The vibration example in the switchbrew/switch-examples doesn't work. Both hidInitializeVibrationDevices() and hidSendVibrationValues() returned successful code, but vibration does not appear on the joycon.
I had posted an issue in the switchbrew/switch-examples, but not much discussion happened there, so i re-posted here.

Mouse is unusable (positions clamped at 0..1280 and 0..720, no way to read all entries for velocities)

hidReadMouse is useless as it is currently: it doesn't report relative mouse motion dx and dy correctly. It reports velocities and positions, but positions are clamped, and velocities only contain the value of the last entry of 17 entries per frame.

https://switchbrew.github.io/libnx/structHidMouse.html

The mouse report per frame should consist of 17 entries of velocities. Currently, only the latest one can be read out by apps using hidMouseRead. This is not enough detail to calculate accurate dx and dy values.

x and y is fine, but is clamped between 0...1280 and 0..720, so it is useless to read out relative mouse motion dx, dy, regardless of mouse position.

The relevant code is here:

HidMouseEntry *newMouseEntry = &sharedMem->mouse.entries[latestMouseEntry];

A new function is needed, or hidMouseRead could be modified to return all 17 report entries. Then dx and dy could be constructed as sum over ALL the velocity entries, I hope.

set.h have no guardian

The switch/services/set.h doesn't have any include guardian (like pragma once, just like other include files).
As long as it contains some enums and definitions, we should be able to include it in multiple sources file.

Creating an XCI with my homebrew (nso) cause a kernel panic

I decided to try to create an XCI from scratch with my homebrew. I've put my main (nso) and my main.npdm in the exeFS, then I've generated the NCA (I've also generated the control NCA with the nacp file and the icons), and finally I've generated the meta NCA.
I'm able to mount the XCI without problems, but when I boot it, I get this kernel panic:

2001-0125

According to switchbrew this should correspond to :

Process already started/Wrong memory permission?

It would be cool if someone of the devs could give it a look.

Thanks

no sys/lock.h file required by mutex.h

As you likely know, mutex.h is required by switch.h, so it is impossible to do much in a coding environment that passively creates errors. Any address to the issue?

Main thread's thread_ptr is always NULL

This is my situation. I'm using the C11 thread implementation of threads, and I'm running into an issue where I have a thrd_t value that I'm setting, and then later comparing to thrd_current. The issue is that thrd_current for the main thread is always NULL, so there is no way for me to check whether this thrd_t value is NULL, or referring to the main thread.

It would be nice if the main thread also had a Thread structure allocated for it, even if it doesn't do much. Right now I'm getting around it by having a sentinel value for thrd_t to refer to unset.

pmdmnt calls do not seem to work

Right now I'm trying to use pmdmnt stuff to get application process ID. pmdmntGetApplicationPid seems to be returning garbage (right now it just put 0x4f434653 in it). pmdmntGetTitlePid seems to be returning the title ID it was passed in instead of the process ID for the title. I've made sure to run pmdmntInitialize, and I am checking the initialize for errors as well.

C3D BuffInfoAdd question

Hi there, I know this is irrelevant but what does the u64 permutation value do in the BuffInfoAdd function? I dont know what to set it to or what it could be fore. I thought that it might be the size of the array or something but it's not so what exactly is it?

Thanks for your time (-;

hidSetNpadJoyAssignmentModeDual not working in 1.6.0

The functions hidSetNpadJoyAssignmentModeDual followed by hidMergeSingleJoyAsDualJoy are not working anymore in latest release 1.6.0.

However, this was working fine in 1.5.0.

This can be observed even on app start: if the controllers are in single joy con mode, they are not automatically put into dual mode anymore, like it used to be in 1.5.0.

In an app, there is no way to change from single back into dual mode now. It used to work in the following way:

		for (int id=0; id<8; id++) {
			hidSetNpadJoyAssignmentModeDual((HidControllerID) id);
		}
		for (int id=0; id<8; id+=2) {
			hidMergeSingleJoyAsDualJoy((HidControllerID) id, (HidControllerID) (id + 1));
		}

but now this doesn't result in any dual controllers.

[Request] Use built-in controller HOME button light

Cosmetic fun request, the right Joy Con, and Switch Pro Controller have a built-in light blue ring in the HOME button, it seems Nintendo have them for some use in the future but they are sitting there in both controllers. When connected to PC and using them as Steam controller the light turns on.

It could be cool to have an option to turn on/off this light upon Switch boot.

Regards

usbHsAcquireUsbIf doesn't seem to be correct

According to swipc-gen, usbHsAcquireUsbIf has 2 output buffers instead of just 1. However, even with adding a second buffer to the IPC command, the call just ends up zeroing both buffers and not returning a handle, nor an error code.

I tried manipulating the passed in device ID (since it seems to actually be structured as 2 bytes of padding and then a little-endian s16, instead of a full s32), but I could never seem to get different behavior, even with the examples.

Problem with getaddrinfo() and gethostbyname()

I need getaddrinfo for networking in OpenTTD. https://github.com/rsn8887/OpenTTD/blob/836a341b55e46f839d51a4f86635b7ab52925bc9/src/network/core/address.cpp#L248
And in general it would be nice to have it working on the Switch.

However, I seem to have stumbled upon a bug, or I am missing something:

  • int e=getaddrinfo(...); is supposed to return a valid error number e, but gai_strerror(e) gives me "unknown error" clearly something is wrong.
  • I checked that I am submitting a valid address, "content.openttd.org" and valid port 3978. I tried family AF_UNSPEC (default) and AF_INET, to make sure it is not ipv6 that is the problem.
  • The error number I get is "22"
  • The max possible number should be "15", according to https://linux.die.net/man/3/getaddrinfo and the libnx header nx/external/bsd/include/netdb.h
  • It looks to me as if the getaddrinfo implementation is taking that error from sfdnsresGetAddrInfo, which ultimately traces back to ipcparse.
    static inline Result ipcParse(IpcParsedCommand* r) {
  • The rough call sequence initiated internally by getaddrinfo is this: getaddrinfo -> sfdnsresGetAddrInfo -> _sfdnsresDnsRequestCommand -> _sfdnsresDispatchDnsRequest -> _sfdnsresDispatchCommand -> ipcParse and somehow an error 22 pops out in the end.

Which brings me to the questions:

  • Is there anything special I have to do (compiler flags etc.) to make getaddrinfo() work on Switch?
  • Is there any software that used this succesfully?
  • Looking for a working example, I saw that switch-libcurl is configured with "--disable-ipv6 --disable-unix-sockets". Is that maybe related?
  • At least two recent commits seem to have fixed some problems in ipc-related structs by adding the ALIGNED attribute. See 966d554 and 9f45bb4
    In the sequence of function calls initiated via getaddrinfo, a similar structure is used. Could this be related? See here:

static Result _sfdnsresDispatchDnsRequest(IpcCommand *c, SfdnsresRequestResults *ret, const void *raw, size_t raw_size, bool has_serialized_data_out) {

SDMC file (fopen) opening seems broken

I am having issues with latest libnx (1.3) and RyuJinx. In the past SDMC fs loading worked fine, but now I get the following error in RyuJinx on the fopen() line below

00:00:05.873 | 0005 KernelSvc SvcArbitrateLock: Invalid owner thread handle 0x08006e40!`

this piece of code would work fine . Has anything changed with regards to sdmc file management in 1.3? This should be reproducable - please try this code out with RyuJinx (any version) below

`int main(int argc, char **argv)
{
gfxInitDefault();
consoleInit(NULL);

FILE *f = fopen("test.txt","r");

if (f)
{
	printf("SDMC file opened ok\n");		
	fclose(f);
}	 
 

// Main loop
while(appletMainLoop())
{
	//Scan all the inputs. This should be done once for each frame
	hidScanInput();

	//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
	u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);

	if (kDown & KEY_PLUS) break; // break in order to return to hbmenu

	gfxFlushBuffers();
	gfxSwapBuffers();
	gfxWaitForVsync();
}

gfxExit();
return 0;

}`

Edit: if i link with libnx V1.21 it opens the file normally as expected

AUDREN_CONSTEXPR breaks pre-C++14 builds

AUDREN_CONSTEXPR in switch/services/audren.h is defined as constexpr for C++ code. However, audrenGetInputParamSize and audrenGetOutputParamSize are more complex constexpr functions which are only supported since C++14. The switch-examples template Makefile uses -std=gnu++11 for C++ code, breaking the build:

/opt/devkitpro/libnx/include/switch/services/audren.h: In function 'constexpr size_t audrenGetInputParamSize(const AudioRendererConfig*)':
/opt/devkitpro/libnx/include/switch/services/audren.h:305:1: error: body of 'constexpr' function 'constexpr size_t audrenGetInputParamSize(const AudioRendererConfig*)' not a return-statement
 }
 ^
/opt/devkitpro/libnx/include/switch/services/audren.h: In function 'constexpr size_t audrenGetOutputParamSize(const AudioRendererConfig*)':
/opt/devkitpro/libnx/include/switch/services/audren.h:318:1: error: body of 'constexpr' function 'constexpr size_t audrenGetOutputParamSize(const AudioRendererConfig*)' not a return-statement
 }

AUDREN_CONSTEXPR should be guarded by the appropriate feature test macros, e.g.:

#if defined(__cplusplus) && (__cpp_constexpr >= 201304)
#define AUDREN_CONSTEXPR constexpr
#else
#define AUDREN_CONSTEXPR static inline
#endif

Also, should the template Makefiles be updated to use C++17 by default?

Error 2345-0021: libnx failed to map code memory

I was using fusee/hekate to launch Homebrew Launcher 2.0 on my switch (vers 5.0.2) and all seemed to work well. HBL would launch, I could launch other .nro's using it (specifically TuxSH's ftpd) but after a while I started getting error 2345-0021. After consulting to the wiki, I determined this was due to libnx failing to map the code memory. It's happening consistently now, within seconds of homebrew launching, the app will spew the error.

Since the error code pinned its problem on libnx, I figured I'd create an issue here to resolve the problem. Below are the steps to reproduce.

  1. Download files from Jan4V/hekate-ipl-50x.
  2. Place contents of zip on the root of SD. Insert card into switch.
  3. Boot into RCM and flash the payload from earlier using fusee-launcher. Boot into CFW.
  4. Launch the album applet. After using FTPD for a while, my switch seemed to start crashing.

If there's anything else you all need of me or any way I can help, let me know!

Nonblocking sockets are not working

Observed behavior:
Using a non-blocking socket with connect to google.com:80 always returns -1.

Expected behavior:
After a certain delay, it is expected that retrying the call to connect on the same sockfd would succeed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.