mailing list of musl libc
 help / color / mirror / code / Atom feed
* semtcl for x86_64
@ 2012-09-22  8:26 Jens
  2012-09-22  9:17 ` Jens
  2012-09-22 12:14 ` Jens
  0 siblings, 2 replies; 8+ messages in thread
From: Jens @ 2012-09-22  8:26 UTC (permalink / raw)
  To: musl


Hello I have some trouble getting semctl working:

Tried in both musl and uclibc to compare.
See below.

The only difference I can see is the IPC_64 flag.

(I haven't tried 32-bit).

Regards,
Jens

program:
bash-4.1# cat t.c
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>

main() {
 	int sem;
//  semget(IPC_PRIVATE, 1, IPC_CREAT|0600) = 131076
   sem = semget(IPC_PRIVATE, 1, IPC_CREAT);
   semctl(sem, 0, SETVAL, 0x1);

}

musl:

bash-4.1# /bin64/strace ./m
execve("./m", ["./m"], [/* 19 vars */]) = 0
semget(IPC_PRIVATE, 1, IPC_CREAT|0)     = 327688
semctl(327688, 0, IPC_64|SETVAL, 0x1)   = -1 EINVAL (Invalid argument)
exit_group(-1)                          = ?
bash-4.1#


uclibc:

semget(IPC_PRIVATE, 1, IPC_CREAT|0)     = 262150
semctl(262150, 0, SETVAL, 0x1)          = 0
_exit(0)                                = ?
bash-4.1#


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22  8:26 semtcl for x86_64 Jens
@ 2012-09-22  9:17 ` Jens
  2012-09-22 12:04   ` Rich Felker
  2012-09-22 12:14 ` Jens
  1 sibling, 1 reply; 8+ messages in thread
From: Jens @ 2012-09-22  9:17 UTC (permalink / raw)
  To: musl



On Sat, 22 Sep 2012, Jens wrote:

>
> Hello I have some trouble getting semctl working:
>
> Tried in both musl and uclibc to compare.

Forgot to mention its musl 0.9.6.

Cheers,
Jens


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22  9:17 ` Jens
@ 2012-09-22 12:04   ` Rich Felker
  2012-09-22 12:17     ` Jens
  2012-09-22 17:09     ` Jens
  0 siblings, 2 replies; 8+ messages in thread
From: Rich Felker @ 2012-09-22 12:04 UTC (permalink / raw)
  To: musl

On Sat, Sep 22, 2012 at 11:17:14AM +0200, Jens wrote:
> 
> 
> On Sat, 22 Sep 2012, Jens wrote:
> 
> >
> >Hello I have some trouble getting semctl working:
> >
> >Tried in both musl and uclibc to compare.
> 
> Forgot to mention its musl 0.9.6.
> 
> Cheers,
> Jens

Should be fixed now... Please let me know if it's still broken.

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22  8:26 semtcl for x86_64 Jens
  2012-09-22  9:17 ` Jens
@ 2012-09-22 12:14 ` Jens
  1 sibling, 0 replies; 8+ messages in thread
From: Jens @ 2012-09-22 12:14 UTC (permalink / raw)
  To: musl


This is dependent on kernel config option ARCH_WANT_IPC_PARSE_VERSION.

Looks like it is not set for x86_64.
select ARCH_WANT_IPC_PARSE_VERSION if X86_32

Looking at the code:
#ifndef CONFIG_ARCH_WANT_IPC_PARSE_VERSION
   /* On IA-64, we always use the "64-bit version" of the IPC structures. 
*/
# define ipc_parse_version(cmd) IPC_64
#else
int ipc_parse_version (int *cmd);
#endif


SYSCALL_DEFINE(semctl)(int semid, int semnum, int cmd, union semun arg)
{
         int err = -EINVAL;
         int version;
         struct ipc_namespace *ns;

         if (semid < 0)
                 return -EINVAL;

         version = ipc_parse_version(&cmd);
...
        switch(cmd) {
...
         case SETVAL:
         case SETALL:
                 err = semctl_main(ns,semid,semnum,cmd,version,arg);
 	        return err;
...
         default:
 	        return -EINVAL;
         }
}

So IPC_64 will not be cleared from cmd since parse_version do not remove 
the bit since its only a macro that returns IPC_64.

Hence EINVAL.

Regards,
Jens

On Sat, 22 Sep 2012, Jens wrote:

>
> Hello I have some trouble getting semctl working:
>
> Tried in both musl and uclibc to compare.
> See below.
>
> The only difference I can see is the IPC_64 flag.
>
> (I haven't tried 32-bit).
>
> Regards,
> Jens
>
> program:
> bash-4.1# cat t.c
> #include <sys/types.h>
> #include <sys/ipc.h>
> #include <sys/sem.h>
>
> main() {
> 	int sem;
> //  semget(IPC_PRIVATE, 1, IPC_CREAT|0600) = 131076
>  sem = semget(IPC_PRIVATE, 1, IPC_CREAT);
>  semctl(sem, 0, SETVAL, 0x1);
>
> }
>
> musl:
>
> bash-4.1# /bin64/strace ./m
> execve("./m", ["./m"], [/* 19 vars */]) = 0
> semget(IPC_PRIVATE, 1, IPC_CREAT|0)     = 327688
> semctl(327688, 0, IPC_64|SETVAL, 0x1)   = -1 EINVAL (Invalid argument)
> exit_group(-1)                          = ?
> bash-4.1#
>
>
> uclibc:
>
> semget(IPC_PRIVATE, 1, IPC_CREAT|0)     = 262150
> semctl(262150, 0, SETVAL, 0x1)          = 0
> _exit(0)                                = ?
> bash-4.1#
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22 12:04   ` Rich Felker
@ 2012-09-22 12:17     ` Jens
  2012-09-22 12:25       ` Rich Felker
  2012-09-22 17:09     ` Jens
  1 sibling, 1 reply; 8+ messages in thread
From: Jens @ 2012-09-22 12:17 UTC (permalink / raw)
  To: musl



On Sat, 22 Sep 2012, Rich Felker wrote:

> On Sat, Sep 22, 2012 at 11:17:14AM +0200, Jens wrote:
>>
>>
>> On Sat, 22 Sep 2012, Jens wrote:
>>
>>>
>>> Hello I have some trouble getting semctl working:
>>>
>>> Tried in both musl and uclibc to compare.
>>
>> Forgot to mention its musl 0.9.6.
>>
>> Cheers,
>> Jens
>
> Should be fixed now... Please let me know if it's still broken.

Ah. great! And I just finished the analysis.. :-)

Thanks,
Jens

>
> Rich
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22 12:17     ` Jens
@ 2012-09-22 12:25       ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2012-09-22 12:25 UTC (permalink / raw)
  To: musl

On Sat, Sep 22, 2012 at 02:17:08PM +0200, Jens wrote:
> 
> 
> On Sat, 22 Sep 2012, Rich Felker wrote:
> 
> >On Sat, Sep 22, 2012 at 11:17:14AM +0200, Jens wrote:
> >>
> >>
> >>On Sat, 22 Sep 2012, Jens wrote:
> >>
> >>>
> >>>Hello I have some trouble getting semctl working:
> >>>
> >>>Tried in both musl and uclibc to compare.
> >>
> >>Forgot to mention its musl 0.9.6.
> >>
> >>Cheers,
> >>Jens
> >
> >Should be fixed now... Please let me know if it's still broken.
> 
> Ah. great! And I just finished the analysis.. :-)

Basically, some archs (approximately the 32-bit ones) have ancient
legacy versions of the IPC structures that only support 16-bit
uid/gid, etc. musl does not support using these, and always uses the
modern structures, which requires the IPC_64 flag (0x100) when making
the syscall. I assumed this flag would be a no-op on systems where
it's not needed, but for some reason the kernel rejects it, so we have
to go to the trouble of omitting it..

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22 12:04   ` Rich Felker
  2012-09-22 12:17     ` Jens
@ 2012-09-22 17:09     ` Jens
  2012-09-22 20:09       ` Rich Felker
  1 sibling, 1 reply; 8+ messages in thread
From: Jens @ 2012-09-22 17:09 UTC (permalink / raw)
  To: musl



On Sat, 22 Sep 2012, Rich Felker wrote:

> On Sat, Sep 22, 2012 at 11:17:14AM +0200, Jens wrote:
>>
>>
>> On Sat, 22 Sep 2012, Jens wrote:
>>
>>>
>>> Hello I have some trouble getting semctl working:
>>>
>>> Tried in both musl and uclibc to compare.
>>
>> Forgot to mention its musl 0.9.6.
>>
>> Cheers,
>> Jens
>
> Should be fixed now... Please let me know if it's still broken.

Now I ran into shmctl which I think have the same problem.

Regards,
Jens

>
> Rich
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: semtcl for x86_64
  2012-09-22 17:09     ` Jens
@ 2012-09-22 20:09       ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2012-09-22 20:09 UTC (permalink / raw)
  To: musl

On Sat, Sep 22, 2012 at 07:09:12PM +0200, Jens wrote:
> >Should be fixed now... Please let me know if it's still broken.
> 
> Now I ran into shmctl which I think have the same problem.

Fixed. I missed it because I grepped for 0x100...

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-09-22 20:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-22  8:26 semtcl for x86_64 Jens
2012-09-22  9:17 ` Jens
2012-09-22 12:04   ` Rich Felker
2012-09-22 12:17     ` Jens
2012-09-22 12:25       ` Rich Felker
2012-09-22 17:09     ` Jens
2012-09-22 20:09       ` Rich Felker
2012-09-22 12:14 ` Jens

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).