Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Contents Causing Duplicate Function Definitions #3

Open
Crypto2099 opened this issue Jul 25, 2024 · 4 comments
Open

Patch Contents Causing Duplicate Function Definitions #3

Crypto2099 opened this issue Jul 25, 2024 · 4 comments

Comments

@Crypto2099
Copy link

The included "temporary fixes" here are causing duplicated function definitions when this patch is used during the JS build for cardano-addresses as referenced here: IntersectMBO/cardano-addresses#264 and here: IntersectMBO/cardano-addresses#267.

It is unclear where else in GHCJS these functions, specifically: geteuid(), sysconf(), getpwuid_r(), and foundation_sysrandom_linux() are being included from.

+// temporary fixes
+
+// XXX fix this in thrunner.js probably
+if(typeof __dirname == 'undefined') {
+ var __dirname = '/';
+}
+
+// TODO: remove
+// TODO: stub, add real implementation
+function h$geteuid() {
+ return 1;
+}
+
+// TODO: stub, add real implementation
+function h$sysconf() {
+ return 0;
+}
+
+// TODO: stub, add real implementation
+function h$getpwuid_r(uid, pwd_d, pwd_o, buf_d, buf_o, buflen, result_d, result_o) {
+ var i, name = h$encodeUtf8("user"), max = Math.min(72, pwd_d.len);
+ if(!result_d.arr) result_d.arr = [];
+ result_d.arr[0] = [pwd_d, pwd_o];
+ if(!pwd_d.arr) pwd_d.arr = [];
+ // we don't really know where the pointers to strings are supposed to go,
+ // so we just point to our dummy string everywhere
+ for(i = 0; i < max; i+=4) pwd_d.arr[i+pwd_o] = [name, 0];
+ for(i = 0; i < (max>>2); i++) pwd_d.i3[i+(pwd_o>>2)] = 1;
+ return 0;
+}
+
+// TODO: move to foundation
+function h$foundation_sysrandom_linux(buf_d, buf_o, size) {
+ cryptoObj.getRandomValues(typedArray);
+}

@Crypto2099
Copy link
Author

The first three functions: geteuid(), sysconf(), and getpwuid_r() are already covered via the unix shim in ghcjs core: https://github.com/ghcjs/ghcjs/blob/b7711fbca7c3f43a61f1dba526e6f2a2656ef44c/lib/boot/shims/pkg/unix.js.pp#L14-L34

@luite
Copy link
Contributor

luite commented Aug 5, 2024

We don't use the shims anymore in the JS backend. The unix package contains its own jsbits now.

Do you still run into this? Perhaps there's another place that needs a fix.

@Crypto2099
Copy link
Author

Sorry for the long delay here but finally getting back to this.

Still finding an issue that can only point to this cryptonite-0.30.patch file but now the duplicated function in question is: h$foundation_sysrandom_linux

+// TODO: move to foundation
+function h$foundation_sysrandom_linux(buf_d, buf_o, size) {
+ cryptoObj.getRandomValues(typedArray);
+}

This is causing issues w/ the jsapi build of https://github.com/IntersectMBO/cardano-addresses

@Crypto2099
Copy link
Author

Seems to be related to the issue that the function is also declared here in the foundation patch? These are the two exact copies of the function that are both appearing the compiled js file:

+// EMCC:EXPORTED_FUNCTIONS _foundation_rngV1_generate
+
+function h$foundation_sysrandom_linux(buf_d, buf_o, size) {
+ return -19; // ENODEV; foundation returns the same for non-linux hosts.
+}
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants